0

I'm new to nginx configuration. There are a static HTML file: index.html and a tomcat server for dynamic pages. I want:

  • When access http://example.com/ or http://example.com/index.html, the static index.html file should be returned.
  • Otherwise, send request to tomcat server.

My config is below: (it works but ugly, please give me a beautiful version)

server {
    listen 80;
    server_name example.com;

    location = / {
        index index.html;
    }

    location = /index.html {
        root /static_dir;
    }

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://host:port; # point to tomcat server
    }
}

nginx makes me really confused. Is there any good way to debug the configuration? For example, tell me which rules are involved and which one is selected.

2
  • Looks OK. But I would put index and root directives to server level and have exact locations empty.
    – Alexey Ten
    Mar 5, 2015 at 15:15
  • Also, usually nginx is configured to serve all static files (htmls, scripts, styles, images).
    – Alexey Ten
    Mar 5, 2015 at 15:16

0

You must log in to answer this question.

Browse other questions tagged .