gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:33:02 25 4
gpt4 key购买 nike

我有一个在端口 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com