Skip to content

Instantly share code, notes, and snippets.

@sentience
Created May 23, 2013 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sentience/5635070 to your computer and use it in GitHub Desktop.
Save sentience/5635070 to your computer and use it in GitHub Desktop.
My nginx config for a unicorn-hosted Rails app. Hitting unicorn directly serves the application; however, attempting to load it via nginx produces a “directory index of … is forbidden” error as shown below. If I put an index.html file in the applicaiton’s `public` directory, nginx serves it fine.
2013/05/23 08:12:15 [error] 19732#0: *1 directory index of "/var/www/leakcrawler/current/public/" is forbidden, client: 58.6.229.249, server: leakcrawler.example.com, request: "GET / HTTP/1.1", host: "leakcrawler.example.com"
upstream unicorn {
server unix:/tmp/unicorn.leakcrawler.sock fail_timeout=0;
}
server {
listen 80 default deferred;
server_name leakcrawler.example.com;
root /var/www/leakcrawler/current/public;
location / {
gzip_static on;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
@sentience
Copy link
Author

Success!!!

These lines were at fault:

  location / {
    gzip_static on;
  }

Removing them fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment