configurationnginx为tomcat / uWSGI代理

我正在为java和django开发configuration一台amazon EC2机器。 我们select的栈是nginx作为80端口上的顶级监听器,并将请求传递给相应的应用程序,thro:8080代表tomcat,thro代表uWSGI的.sock。

我有nginxconfiguration如下:

server { listen 80; server_name test.myproject.com; rewrite ^/(.*)$ /myproject/$1; location / { proxy_pass http://127.0.0.1:8080/; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; server_name test.myotherproject.com; rewrite ^/(.*)$ /myotherproject/$1; location / { proxy_pass http://127.0.0.1:8080/; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; server_name web1.myhost.com.br; location /static/ { root /home/ubuntu/projects/hellow/; } location / { uwsgi_pass unix:/var/run/uwsgi.sock; include uwsgi_params; uwsgi_param SCRIPT_NAME ''; } } 

第一个“服务器”条目redirect到一个tomcat的web应用程序.war,并完美地工作。 第三是重新导向到uWSGI袜子,它也工作正常。 第二个是问题。 它被configuration为与第一个相同的方式,但是当我访问http://test.myotherproject.com我的浏览器给我一个404以下消息:

  HTTP Status 404 - /myotherproject/myotherproject/user/redirectPermission type Status report message /myotherproject/myotherproject/user/redirectPermission description The requested resource is not available. Apache Tomcat/7.0.33 

/ user / redirectPermission是一个有效的页面,它是应用程序在第一次访问时去那里的预期行为,以获得用户authentication。 问题是第二个/ myotherproject /部分被追加,我无法弄清楚为什么发生这种情况。 请注意,给了我以上404的url是: http : //test.myotherproject.com.br/myotherproject/user/redirectPermission 。 另外,tomcat在server.xml文件中没有额外的configuration,除了将其端口更改为8080,并且在webbapps及其名为myotherproject.war(tomcat7.x / webapps / myotherproject.war)的战争中。 有谁知道如何正确configuration此设置? 在此先感谢,丹参

你可以进行一个简单的testing吗?

 $ curl -I http://test.myproject.com/myproject $ curl -I http://test.myotherproject.com/myotherproject 

第二个输出(如果我是对的)正在向/ myotherproject / user / redirectPermission返回一个301(或类似的),通过重写规则将其重写为/ myotherproject / myotherproject / user / redirectPermission:

 rewrite ^/(.*)$ /myotherproject/$1; 

如果确实是这个问题,一个解决scheme是使这两个应用程序在根上下文中被服务,但是在Tomcat上被configuration为虚拟主机,以便根据主机头来决定要提供哪个应用程序(您可能需要传递这个头文件显式从nginx到Tomcat)。

但是正确的解决scheme是将整个请求转发到基于位置规则的Tomcat,并让Tomcat按照自己想要的方式进行处理。

您可以尝试更改proxy_pass位置而不是重写规则:

 proxy_pass http://127.0.0.1:8080/myotherproject/; 

myotherproject的第二部分可能被附加到Tomcat应用程序规则中。