Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...