8

I am new to Nginx and I need your help,

According to many forums I understood that all our static pages are stored in Nginx. When there is request comes I have to pass that request to tomcat for data and after response from tomcat response generated.

Currently, I have just done that I request directly passed to tomcat and respond to request. but I think that is not solution for performance.

So anyone can Help me?

sanghavi7
  • 758
  • 1
  • 15
  • 38

1 Answers1

14

You can using proxy_pass mapping to your tomcat server port, for example : if your tomcat port is 8080, your conf/nginx.conf should be configured like this:

...
http {
    ...

    server {
        location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

restart it sbin/nginx -s reload, then when you can access http://127.0.0.1, the request forward to tomcat.

Configuration file is placed commonly under:

/etc/nginx/nginx.conf
Athlan
  • 6,389
  • 4
  • 38
  • 56
Jason
  • 1,241
  • 8
  • 16
  • hey jason thnx for reply, any change I have to do in server.xml file? – sanghavi7 Jul 10 '12 at 10:30
  • You do not have to change server.xml. – Jason Jul 10 '12 at 11:04
  • hey Jason thnx for reply, but there is one problem, solution given by you works fine but the action is not fired... – sanghavi7 Jul 10 '12 at 13:09
  • so what I have to do for that? – sanghavi7 Jul 10 '12 at 13:10
  • hey Jason thnx for reply, but there is one problem, solution given by you works fine but the action is not fired... what I mean to say is whatever action fired in those are not getting response or everytime it come to login page. – sanghavi7 Jul 10 '12 at 13:41
  • I don't understand your problem, If request already forward to tomcat, you should focus your web server code. 1 IF request not response,check tomcat status. 2 When it come to login page everytime, check your code if any filter works. – Jason Jul 11 '12 at 01:42
  • ok ok, every time when I trying to login into application it will redirect to login page only.. and let me check my code first – sanghavi7 Jul 11 '12 at 04:39
  • in root attribute, is it needed absolute path or relative path? – sanghavi7 Jul 11 '12 at 05:58
  • where I have to put my static resources for NGINX and for that all configuration code? – sanghavi7 Jul 13 '12 at 05:36