当Nginx反向代理在前面时,告诉lighttpd使用的协议(HTTPS)

问题描述 投票:0回答:1

我有一个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忽略了Nginx发送的X-Forwarded-Proto标头。

我究竟做错了什么?是否还有其他配置要做?谢谢。

https lighttpd web.py nginx-reverse-proxy
1个回答
0
投票

您必须将lighttpd配置为信任来自上游的标头。在lighttpd中使用mod_extforward。见https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModExtForward

比上面的许多标题更好,nginx和lighttpd(通过mod_extforward)都支持RFC 7239 Forwarded标头。

https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/

应优先使用“转发”标题。

© www.soinside.com 2019 - 2024. All rights reserved.