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,目前还没有。有什么想法吗?

答案1

可能需要调整 proxy_redirect 或 gitorious 中的某些配置,您能否窥探从前端到后端的请求/响应流量以查看 gitorious 发出的确切重定向?

相关内容