Nginx下载tomcat index.jsp而不是服务它

时间:2016-01-03 20:25:03

标签: tomcat nginx configuration

我尝试在Tomcat中使用Nginx vhost webapp,我的vhost配置文件:

server {
    listen   80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name *.a.com;

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

    root   /opt/javaee/shared/shared1/apache-tomcat-8.0.30/webapps/testapp1; 
    index  index.html index.jsp;

    location / {

       rewrite ^ /testapp1$1 last;


       proxy_set_header   Host               $http_host;
       proxy_set_header   X-Real-IP          $remote_addr;
       proxy_set_header   X-Forwarded-Server $host;
       proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
       proxy_pass         http://localhost:8080;
       proxy_redirect     off;
   }

 }

当我在浏览器中请求a.com时,它会继续下载index.jsp而不是为该页面提供服务。当我请求localhost:8080/testapp1时,一切正常。请有任何见解。

1 个答案:

答案 0 :(得分:1)

sort(A,'descend')看起来完全错了。一切都在无限循环中重写为1 2 3 5 6 4 7 8 9 。我很惊讶它可以提供任何服务。

如果您希望将rewrite ^ /testapp1$1 last;(且仅/testapp1)映射到内部路径/,请使用:

/

如果您希望在上游发送之前将所有内容都加上/testapp1作为前缀,请使用:

location = / { rewrite ^ /testapp1 last; }
location / {
    proxy_set_header   Host               $http_host;
    proxy_set_header   X-Real-IP          $remote_addr;
    proxy_set_header   X-Forwarded-Server $host;
    proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_pass         http://localhost:8080;
    proxy_redirect     off;
}