Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

apache - Proxy not redirecting

I have the following Apache config file. When someone types in http://mywebsite.com it is not redirecting them to https. Why?

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass "/" "http://10.0.1.123/"
    ProxyPassReverse "/" "http://10.0.1.123/"
    ServerName www.mywebsite.com
    ServerAlias mywebsite.com
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =mywebsite.com
    RewriteCond %{SERVER_NAME} =www.mywebsite.com
    RewriteRule ^ https://mywebsite.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLProxyEngine on
    ProxyPreserveHost On
    ProxyPass "/" "http://10.0.1.123:80/"
    ProxyPassReverse "/" "http://10.0.1.123:80/"
    ServerName www.mywebsite.com
    ServerAlias mywebsite.com
    ServerAdmin [email protected]
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/www.mywebsite.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.mywebsite.com/privkey.pem
</VirtualHost>
question from:https://stackoverflow.com/questions/65650325/proxy-not-redirecting

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<VirtualHost *:80>
    ... 
    ProxyPass "/" "http://10.0.1.123/"
    ...
    RewriteRule ^ https://mywebsite.com%{REQUEST_URI} [END,NE,R=permanent]

The ProxyPass is telling Apache to work as reverse proxy and forward the request to the real server. The RewriteRule instead is telling Apache to answer the request itself with a redirect to the HTTPS version of the site. Obviously it cannot do both at the same time, so there is a conflict. Please remove Proxy* rules and keep only the Rewrite* rules on port 80.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...