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

时间:2014-05-28 18:38:27

标签: tomcat nginx

我让Nginx坐在我的Tomcat服务器前面。我可以通过转到http://myhost.example.com/myapp来访问我的应用,但我最好只是浏览http://myhost.example.com而不在网址中添加/ myapp。我似乎无法弄清楚如何做到这一点。

这是我对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;
  }
}

0 个答案:

没有答案