4

我在让我的 nginx + tomcat 7 反向代理设置工作时遇到问题。

基本上我想https://192.168.10.101从上游集群/webapp/提供内容;但是我从我的应用程序中获得了 404 页面。

任何关于出错的提示将不胜感激。

我的配置如下。

server {

            server_name 192.168.10.101;
            access_log /var/log/nginx/mysite-access.log;
            listen   443;
            ssl on;
            ssl_certificate    /etc/nginx/ssl/mysite.crt;
            ssl_certificate_key    /etc/nginx/ssl/private/mysite_pvt.key;

                location  / {
                        proxy_redirect off;
                        proxy_pass      https://tccluster/webapp/;
                        rewrite_log     on;

                        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;

                }
}

upstream  tccluster  {
                server   192.168.56.103:8443;
                server   192.168.56.104:8443;
}
4

2 回答 2

7

终于想通了。该应用程序有一个重定向到的过滤器/webapp/index.html,这使得 nginx 发出请求,/webapp/webapp/index.html它给出了 404。

我添加了重写规则

location / {
                proxy_pass  https://backend/webapp/;
                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;
                rewrite ^/webapp/(.*)$ /$1 last;
}

这似乎现在有效!

于 2013-09-22T01:00:50.293 回答
2

完整的 nginx 配置传递给 tomcat 上下文:

server {
  listen 80;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  listen [::]:80;
  server_name tomcat-context.domain.com ;

  # individual nginx logs for this vhost
  access_log  /var/log/nginx/tomcat-context_domain_access.log main;
  error_log   /var/log/nginx/tomcat-context_domain_error.log;



    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }
    location / {
                proxy_pass  http://127.0.0.1:10080/tomcat-context/;
                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;
                rewrite ^/tomcat-context/(.*)$ /$1 last;
    }
    location /tomcat-context {
      rewrite ^/tomcat-context(.*)$ $1  redirect;
    }
}
于 2016-02-29T20:07:53.927 回答