HTTPS使用非443端口登录页跳转出错的解决

使用nginx部署的HTTPS。由于宽带443也开始被封杀,HTTPS使用了一个非443端口(例如1234),之前一直正常。升级到最新版本建议改用WSGI后发现如果用户未登录,访问https://xxx:1234后,登录页面会跳转到http://xxx/accounts/login/?next=/(没带端口号),导致出错。

最后发现是nginx配置问题,服务升级指引(https://manual.seafile.com/changelog/server-changelog.html
http://manual-cn.seafile.com/deploy/https_with_nginx.html )中因为是使用标准443端口所以没有这个问题,需要修改配置为
proxy_set_header Host $http_host; (优选,理由:https://stackoverflow.com/questions/15414810/whats-the-difference-of-host-and-http-host-in-nginx, 感谢lian的建议)

proxy_set_header Host $host:$server_port;

这样在传递请求到后端seafile的时候才会携带上正在使用的非443端口号。

1 个赞

gogogo @lian

你看一下这里 https://github.com/haiwen/seafile-docs/pull/395#issuecomment-341611729

The server_port field is the port the server is listening rather than the client is accessing.
If I set up a server listening on port 443, but outside NAT redirects public port 8443 to our 443, then clients will be connecting to 443 which will not work.