NGINX反向代理不保留正确的HostName

时间:2015-08-26 21:40:03

标签: tomcat nginx jira reverse-proxy

我在/etc/nginx/sites-enabled/default

中添加了以下配置
upstream jira  {
      server xx.xx.xx.xx:8080;
}

# redirect non-ssl Jira to ssl
server {
    listen 80;
    server_name  jira.example.com;
    rewrite ^(.*) https://jira.example.com$1 permanent;
}

#
# The Jira server
#
server {
    listen       xx.xx.xx.xx:443;
    server_name  jira.example.com;

    ssl on;

    access_log  /var/log/nginx/jira.access.log;
    error_log   /var/log/nginx/jira.error.log;

    location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://jira;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        proxy_buffering off;

        # Password
        auth_basic "Restricted";
        auth_basic_user_file /etc/apache2/.htpasswd;

        # Don't forward auth to Tomcat
        proxy_set_header   Authorization "";
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

但由于某种原因,在NGINX授权之后,它只会重定向到:htttp://jira/secure/MyJiraHome.jspa。不保留https和服务器名称。可能我在配置中做错了什么。请帮忙。

提前致谢。

0 个答案:

没有答案