我在端口8080上运行了一个烧瓶应用程序,我想将Apache用作反向代理,并将http重定向到https。
“/ example.conf的/ etc / apache2的/启用的站点 - ”
<VirtualHost *:80>
ServerAdmin support@example.com
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ErrorLog /home/helloworld/logs/error.log
CustomLog /home/helloworld/logs/access.log combined
SSLEngine on
SSLCertificateFile /home/helloworld/certs/cert.pem
SSLCertificateKeyFile /home/helloworld/certs/key.pem
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
我也有一个工作的nginx配置来做同样的事情,但我想在生产中使用apache。 这是nginx配置
server {
listen 80;
server_name _;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name _;
ssl_certificate /home/helloworld/certificate/cert.pem;
ssl_certificate_key /home/helloworld/certificate/key.pem;
access_log /var/log/ex_access.log;
error_log /var/log/ex_error.log;
location / {
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
答案 0 :(得分:0)
而不是仅匹配/的Redirect
,这应该更好(但还有其他方法可以做同样的事情):
RewriteEngine On
RewriteRule ^/.*$ http://example.com/$1 [R=301,L]