Nginx
nginx 反向代理子域正在重定向
所以我有一個前端 nginx 伺服器,它將代理到其他幾個 nginx 伺服器(執行 Passenger for Rails 應用程序)。
這是有問題的前端 nginx 配置的一部分:
server { listen 80; server_name git.domain.com; access_log /server/domain/log/nginx.access.log; error_log /server/domain/log/nginx_error.log debug; location / { proxy_pass http://127.0.0.1:8020/; 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; proxy_max_temp_file_size 0; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } } server { listen 80; server_name domain.com; access_log /server/domain/log/nginx.access.log; error_log /server/domain/log/nginx_error.log debug; location / { proxy_pass http://127.0.0.1:8000/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X_FORWARDED_PROTO https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
最後是 git.domain.com 的後端:
server { listen 8020; #server_name localhost; root /server/gitorious/gitorious/public/; passenger_enabled on; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X_FORWARDED_PROTO https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
所以這就是問題所在。當我輸入 git.domain.com 時,我的 gitorious 安裝將重定向到 domain.com。它在那裡完美執行,但它忽略了子域。
一開始我以為是
server_name
構造。我已經嘗試過 git.domain.com、domain.com、localhost,但目前沒有。有任何想法嗎?
可能您需要調整 proxy_redirect 或一些配置,您可以窺探前端到後端的請求/響應流量以查看確切的重定向 gitorious 正在發出嗎?