Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Pardon me, this is my first attempt at Nginx-Jetty instead of Apache-JK-Tomcat.

I deployed myapp.war file to $JETTY_HOME/webapps/, and the app is accessible at the url:

http://myIP:8080/myapp

I did a default installation of Nginx, and the default Nginx page is accessible at myIP

Then, I modified the default domain under /etc/nginx/sites-enabled to the following:

server {
        listen   80;
        server_name mydomain.com;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                #root   /var/www/nginx-default;
                #index  index.html index.htm;
                proxy_pass http://127.0.0.1:8080/myapp/;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /var/www/nginx-default;
        }
}

Now I get the index page of mypp (running in jetty) when I hit myIP, which is good. But all the links are malformed. eg. The link to css is mydomain.com/myapp/css/style.css while what it should have been is mydomain.com/css/style.css. It seems to be mapping mydomain.com to 127.0.0.1:8080 instead of 127.0.0.1:8080/myapp/

Any idea what am missing? Do I need to change anything on the Jetty side too?

share|improve this question

2 Answers 2

It is now not nginx configuration problem but your application or Jetty configuration problem. Your application, running under Jetty still 'thinks' its URL is /myapp/ not /, you should change your application configuration to use right base URL.

Theoretically the server could rewrite the links when passing the application responses back to the clients (Apache with right module can do that, I am not sure about nginx), but that is a good idea only if you cannot fix the application or server you proxy-pass to.

share|improve this answer

You could also use Nginx's rewrite module.

It sounds like your problem is in Jetty, before the application level -- if it weren't, you could use the Tuckey URL rewriting filter. Both are super easy to use. Tuckey is at http ://tuckey.org/urlrewrite/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.