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/
orhttp://example.com/index.html
, the staticindex.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.
index
androot
directives to server level and have exact locations empty.