Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a EC2 ubuntu with Glassfish v3 + Nginx setup to host my java web application. This application is deployed as a WAR file to Glassfish . The NGINX is currenty passing all request to the glasshfish appserver including the ones for static images, css etc. javascripts etc.

server {
  listen  80;

  access_log  /var/log/nginx/;

  location / {
    proxy_pass_header Set-Cookie;
    proxy_pass_header X-Forwarded-For;
    proxy_pass_header Host;


share|improve this question
up vote 3 down vote accepted

I have solved this as follows a) Modify the config file as follows

server {

        listen   80; ## listen for ipv4
        server_name; ## change this to your own domain name
    root   /home/ubuntu/www/public_html;
## Only requests to our Host are allowed i.e., and
      if ($host !~ ^($ ) {
         return 444;

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

    location / {
        access_log off;
        proxy_pass http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /var/www/nginx-default;


b) under the Nginx HTML root (/home/ubuntu/www/public_html)create a subdir with the same name as the context of your web appplication. e.g. if your webpp url is, create a directory called /home/ubuntu/www/public_html/mycoolapp

c) unzip the war file to this folder. Get rid of the WEB-INF folder

d) restart nginx . To verify, stop your web application while keeping NGINX up and access a an image or css from your webapp.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.