0

I am in the process of switching from apache to nginx as reverse proxy as new knowledge has been gained around better resource usage of nginx. Since I have apache experience , it took me some time and research to figure out the root part of the following configuration.

server {
    listen         80;
    server_name    test.myapp.localhost;

    access_log /var/log/nginx/test.myapp.localhost_access.log;
    error_log  /var/log/nginx/test.myapp.localhost_error.log warn;

    root /var/lib/tomcat7/webapps/ROOT;

    location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
      access_log off;
      expires max;
    }

    location / {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://localhost:8080;
  }
}

This configuration without the root directive has issues showing images and I got to understand it's per design as I had to include the tomcat folder as root as well.

This works fine in the case where tomcat and nginx share the same server. What if nginx and tomcat are both on different servers. How files are rendered in that case.

Thanks for reading

black sensei
  • 609
  • 3
  • 10
  • 25
  • 1
    Do you have `proxyName` and `proxyPort` directives set on your tomcat connector? If not then you should try setting them up. – dtoubelis Aug 19 '15 at 20:42
  • Thanks @dtoubelis I have seen the documentation , I have not yet giving it a try. But out of curiosity. What if the remote host is not tomcat but apache? – black sensei Aug 20 '15 at 19:02
  • it will be redirected to apache, so it is not always ideal. – dtoubelis Aug 20 '15 at 19:46
  • The most effective way to investigate this issue is to intercept traffic between apache and tomcat and nginx and tomcat with tcpdump and compare HTTP headers and then adjust nginx configuration to match results from apache. – dtoubelis Aug 20 '15 at 19:51

0 Answers0