Configure nginx for jboss/tomcat
-
In order to pass traffic to JBoss/TomCat on port 80 using Apache we used to install and configure mod_jk. Is there an equivalent for nginx? Basically want all port 80 traffic to be passed to jboss.
-
Answer:
For nginx checkout their docs http://wiki.nginx.org/NginxJavaServers. Proxy support is built in. In the example below from their site, you will see that specific port 80 traffic is being sent to a single servlet container running on port 8080. Note that if you want to run multiple backend servlet containers ( for load balancing, scaling, etc... ) you should look at the http://wiki.nginx.org/NginxHttpUpstreamFairModule that will send traffic to the least-busy backend server. It is not shipped by defaul w/nginx. server { listen 80; server_name YOUR_DOMAIN; root /PATH/TO/YOUR/WEB/APPLICATION; location / { index index.jsp; } location ~ \.do$ { proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } location ~ \.jsp$ { proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } location ^~/servlets/* { proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } }
user76328 at Server Fault Visit the source
Other answers
You can check my blog post on http://www.componentix.com/blog/18. It may be interesting to you, as example includes few additional tweaks as caching content only for not logged in users and redirecting for different languages.
Vladimir Grichina
Another way to do it like it's described in http://wiki.nginx.org/LikeApache wiki page. server { listen myhost:80; server_name myhost; location / { root /path/to/myapp/public; 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://myapp:8080; } } I have as well tested it as well with /myapp instead of root and works as well, putting location /myapp and proxypass http://myapp:8080/myapp; As well, this configuration maps everything to the Java application, which is useful when you have nice URLs that are mapped by an MVC framework like Struts.
Marc Climent
You don't have to use mod_jk, you can use mod_proxy, i.e. pass the traffic through over HTTP instead of AJP. If nginx has proxy ability, that should work just as well.
skaffman
There is now a pretty fresh ajp_module for nginex. I dont have experience with it, but I think the session stickyness and especially the persistent backend connections are quite helpfull for Tomcat. Both methods (http proxy or ajp proxy) are sadly inflexible for longrunning queries (comet) or large file transfers (uploads). https://github.com/yaoweibin/nginx_ajp_module#readme lighthttp BTW has a general proxy module which can handle FCGI,HTTP,CGIS and AJP13 encoding. This looks like a better approach (but I think from reading it has the same limitations with regards to untypical long/large request/response patterns). http://redmine.lighttpd.net/wiki/1/Docs:ModProxyCore
eckes
Related Q & A:
- How to deploy my jboss servlets to GoDaddy and make it available to my Android client?Best solution by Webmasters
- How to make nginx to redirect multiple subdomains?Best solution by stackoverflow.com
- Why JBoss Fuse is a best ESB?Best solution by jboss.org
- How can I do nginx rewrite?Best solution by Server Fault
- How to allow specific IP access in Nginx?Best solution by Server Fault
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.