Nginx config - serving index.html not working

Posted by Bill on Server Fault See other posts from Server Fault or by Bill
Published on 2012-06-19T02:33:48Z Indexed on 2012/06/19 3:17 UTC
Read the original article Hit count: 175

Filed under:

I can't figure out how to redirect / to index.html. I've gone through the threads on serverfault and I think I've tried every suggestion including:

  • rewrite statements within location /
  • index index.html at the server level, within location / and within static content
  • moving node.js proxy statements to location ~ /i instead of within location /

Obviously something is wrong somewhere else in my configuration. Here is my nginx.conf:

worker_processes  1;

pid        /home/logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include            mime.types;
    default_type       application/octet-stream;
    sendfile           on;
    keepalive_timeout  65;

    error_log   /home/logs/error.log;
    access_log  /home/logs/access.log combined;

    include sites-enabled/*;
}

and my server config located in sites-enabled

server {
  root        /home/www/public;
  listen      80;
  server_name localhost;

  # proxy request to node
  location / {
    index index.html index.htm;
    proxy_set_header   Host             $http_host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header   X-NginX-Proxy    true;

    proxy_pass         http://127.0.0.1:3010;
    proxy_redirect     off;
    break;
  }  

  #  static content
  location ~ \.(?:ico|jpe?g|jpeg|gif|css|png|js|swf|xml|woff|eot|svg|ttf|html)$ {
    access_log  off;
    add_header  Pragma public;
    add_header  Cache-Control public;
    expires     30d;  
  }

  gzip on;
  gzip_vary on;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_min_length  1000;
  gzip_disable     "msie6";
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}

Everything else is working just fine. Requests get proxied to node correctly and static content is served correctly. I just need to be able to forward requests made to / to /index.html.

© Server Fault or respective owner

Related posts about nginx