Apache2从http重写/重定向到https

问题描述 投票:0回答:1

我在Ubuntu上使用apache2,并与letencrypt一起使用acme以保护我的网站。我也想从http://mywebsite.com重定向到https://mywebsite.com,但这不适用于以下配置:

文件名-xy.conf看起来像这样:

<VirtualHost *:80>
    ServerName mywebsite.com

    ProxyRequests off
    ProxyPreserveHost On
    <Location / >
        ProxyPass "ajp://localhost:9090/"
        ProxyPassReverse "ajp://localhost:9090/"
    </Location>
</VirtualHost>

文件名-xy-ssl.conf看起来像这样:

<VirtualHost *:80>
    ServerName mywebsite.com

    RewriteEngine on
    #RewriteCond %{SERVER_NAME} =www.mywebsite.com [OR]
    RewriteCond %{HTTPS} =mywebsite.com
    RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

 # forward ORDS requests to tomcat
 <VirtualHost *:443>
    ServerName mywebsite.com

    # SSL certificates settings
    #Include /etc/apache2/conf-enabled/options-ssl-apache.conf
    SSLCertificateFile /etc/apache2/ssl/mywebsite.com/fullchain.cer
    SSLCertificateKeyFile /etc/apache2/ssl/mywebsite.com/mywebsite.com.key
    SSLCertificateChainFile /etc/apache2/ssl/mywebsite.com/ca.cer

    ProxyRequests on
    ProxyPreserveHost On
    <Location / >
        ProxyPass "ajp://localhost:9090/"
        ProxyPassReverse "ajp://localhost:9090/"
    </Location>
</VirtualHost>

使用此配置,我将导航到默认的apache2主页,https://mywebpage.com正常运行。为了自动从http://mywebsite.com重定向到https://mywebsite.com,此配置有什么问题?

apache2 lets-encrypt acme
1个回答
0
投票

为了处理这种情况,我将我的http vhost设置如下。我不认为它也不需要启用任何新模块,只需像最后一行一样添加重定向语句即可:)

http-config

© www.soinside.com 2019 - 2024. All rights reserved.