我在同一台计算机中有一个nginx反向代理重定向到LightTPD服务器。此反向代理在HTTPS上起作用,因此我想告诉LightTPD,HTTPS用作协议而不是HTTP。这是我的nginx混乱。
server {
server_name mydomain.com;
merge_slashes off;
rewrite ^(.*?)//+(.*?)$ $1/$2 permanent;
location / {
proxy_pass http://localhost:8088/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
# SSL settings
}
server {
if ($host = mydomain.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
}
LightTPD服务器正在运行一个使用 web.py 模块的Python应用程序,但是web.ctx.protocol
返回的值仍然是 http 何时应为 https 。看起来LightTPD忽略了 X-Forwarded Proto NGINX发送的标题。
我在做什么错?还有其他配置需要进行吗?谢谢。
您必须配置LightTPD以信任上游的标头。在LightTPD中使用mod_extforward。请参阅https://redmine.lighttpd.net/projects/lighttpd/wiki/docs_modextforward
比上面的许多标头更好,Nginx和LightTPD(通过mod_extforward)支持RFC 7239转发标头。
https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/
应该首选使用"转发"标头。