apache - 如何使用反向代理配置 apache ssl

标签 apache ssl nginx reverse-proxy

我有一个在端口 8080 上运行的 Flask 应用程序,我想使用 Apache 作为反向代理并将 http 重定向到 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>

我也有一个工作的 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;
    }
}

最佳答案

与仅匹配/的 Redirect 相比,这应该更好(但还有其他方法可以做到这一点):

RewriteEngine On
RewriteRule ^/.*$ http://example.com/$1 [R=301,L]

关于apache - 如何使用反向代理配置 apache ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50867193/

相关文章:

php - PHP "remote include"是如何工作的?

python - 超出 Django 最大递归深度

html - JSF 更改自动生成的元元素以允许使用 ssl 下载文件

mysql - 在所有 MySql 表上要求 SSL

security - 安全代理背后的一切都安全吗?

ruby-on-rails - 多个子域不断重定向到根路径

ubuntu - Django 说所有图像无效,但 PIL 有效

php - CodeIgniter 项目给出 303/压缩错误

php - 找不到 Apache 虚拟主机 404

ssl - 哪种 TLS 方法更适合端口 587?