I have a flask app running on port 8080 and I want to use Apache as a reverse proxy as well as redirect http to https.
"/etc/apache2/sites-enabled/example.conf"
<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>
I also have a working nginx config to do the same this but I want to use apache in production. Here is the nginx config
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;
}
}
Instead of the Redirect
which only matches / , this should be better (but there are other ways to do the same) :
RewriteEngine On
RewriteRule ^/.*$ http://example.com/$1 [R=301,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.