在Nginx的根目录下提供Tomcat应用程序

在Nginx的根目录下提供Tomcat应用程序,tomcat,nginx,Tomcat,Nginx,我让Nginx坐在我的Tomcat服务器前面。我可以通过转到访问我的应用程序,但我希望只浏览到,而不将/myapp添加到URL。我似乎不知道该怎么做 这是我对Tomcat的Nginx配置 upstream stats { ip_hash; server localhost:8080; } server { listen 80; server_name myhost.example.com; access_log /var/log/nginx/stats.access.lo

我让Nginx坐在我的Tomcat服务器前面。我可以通过转到访问我的应用程序,但我希望只浏览到,而不将/myapp添加到URL。我似乎不知道该怎么做

这是我对Tomcat的Nginx配置

upstream stats {
  ip_hash;
  server localhost:8080;
}

server {
  listen 80;
  server_name myhost.example.com;

  access_log /var/log/nginx/stats.access.log;
  error_log /var/log/nginx/stats.error.log debug;

  gzip on;
  gzip_min_length 1000;
  gzip_proxied expired no-cache no-store private auth;
  gzip_types text/css text/html text/plain application/javascript application/xml application/json application/x-font-woff images/png;

  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://stats;
    proxy_redirect off;
  }

  location ~ ^/(images|styles|scripts|views) { 
    root /srv/tomcat/webapps/stats/public;
    log_not_found off;
  }
}

我在config中看不到任何
myapp
,所以您应该将tomcat配置为从root为应用程序服务,而让tomcat从root为应用程序服务是不可取的。刚才我把“代理通行证”改成了“代理通行证”,使它能正常工作。