Jak*_*rds 11 http nginx reverse-proxy http-headers
这个 nginx 实例的目的是让 GitLab 和 OpenWRT Luci 通过反向代理重定向。它已经在其他几个网站上工作,所有网站都有一个基本网址,似乎可以解决这个问题。
示例位置的相关 nginx 配置是;
location /gitlab/ {
proxy_pass http://127.0.0.1:9000/;
proxy_redirect default;
}
Run Code Online (Sandbox Code Playgroud)
有一些标头代理配置选项应用于此位置。
# Timeout if the real server is dead
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
# Basic Proxy Config
proxy_set_header Host $host:$server_port;
proxy_set_header Origin $scheme://$host:$server_port;
proxy_set_header Connection $http_connection;
proxy_set_header Cookie $http_cookie;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Frame-Options SAMEORIGIN;
# Advanced Proxy Config
send_timeout 5m;
proxy_read_timeout 300;
proxy_send_timeout 300;
proxy_connect_timeout 300;
proxy_buffers 32 4k;
proxy_buffer_size 4k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_http_version 1.1;
proxy_cache_bypass $cookie_session;
proxy_no_cache $cookie_session;]
Run Code Online (Sandbox Code Playgroud)
https://127.0.0.1:9000/users/sign_in
当浏览到https://website.com:8080/gitlab/
;
GET /gitlab/ HTTP/1.1
Host: website.com:8080
Run Code Online (Sandbox Code Playgroud)
响应错误地返回到/users/sign_in
而不是/gitlab/users/sign_in
HTTP/1.1 302 Found
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/html; charset=utf-8
Location: https://website.com:8080/users/sign_in
Run Code Online (Sandbox Code Playgroud)
手动浏览到https://website:8080/gitlab/users/sign_in加载页面,但没有资产,因为它们下降直到与上述相同的问题。
阅读nginx docs,它表明默认代理行为应该处理这种情况,尽管它似乎失败了。
日志似乎没有显示太多。
应该采取哪些额外步骤来帮助诊断为什么会发生这种情况?
向proxy_pass
目标添加尾部斜杠。
更新: OP 没有准确说明 vhost 正在接受https
。由于该方案被转发到具有附加标头的后端服务器,因此会出现问题,因为在重写上游回复中的标头时,默认情况下proxy_redirect default;
命令 nginx 期望http 方案Location
,而不是 https。
因此,必须明确地将其更改为更通用的形式(仍然需要尾部斜杠):
location /gitlab/ {
proxy_pass http://127.0.0.1:9000/;
proxy_redirect $scheme://$host:$server_port/ /gitlab/;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
46333 次 |
最近记录: |