title: Nginx + Passenger + Rails - 403 forbidden
body: <p>There are tons of people having the same or similar problem but they all resolved with different solutions. I am having a hard time figuring out what is wrong with my setup here.</p>
  
  <p>I just installed Nginx 1.4.1, Passenger 4.0.7, Ruby 2.0.0p247 and Rails 4.0.0.</p>
  
  <p><strong>Note:</strong></p>
  
  <ul>
  <li>I have installed nginx @ <code>/home/deployer/nginx</code>  </li>
  <li>I am using <code>rubyenv</code>  </li>
  <li>I have a <code>CNAME</code> record for <code>www.example.com</code> that points to <code>myapp.cloud.com</code></li>
  </ul>
  
  <p>I added this block at the end of <code>~/nginx/conf/nginx.conf</code></p>
  
  <pre><code>server {
    listen 80;
    server_name www.example.com;
    root /home/deployer/sites/www.example.com/public;
    passenger_enabled on;
  }
  </code></pre>
  
  <p>I have a <code>public</code> Symlink in <code>/home/deployer/sites/www.example.com</code> that points to <code>/home/deployer/src/myapp/gateway/public/</code></p>
  
  <p>I am having 2 issues:</p>
  
  <ol>
  <li><p>If I do not setup a default <code>root</code> route for my rails app, I do not see the standard <code>Rails Welcome</code> page when I go to the root of my site. Instead, I keep getting the <code>403 Forbidden</code> page. But, if I add an <code>index.html</code> in the <code>public</code> folder, I do see that page being rendered when I go <code>http://www.example.com/</code></p></li>
  <li><p>If I set the default <code>root</code> route to <code>controller#action</code>, I do not see that controller-action being rendered when I go to the root of my site. Instead, this is the error I get in <code>~/nginx/logs/error.log</code>:</p></li>
  </ol>
  
  <hr>
  
  <pre><code>2013/07/08 19:57:05 [error] 34157#0: *1 directory index of
  "/home/deployer/sites/www.example.com/public/" is forbidden, 
  client: 76.XX.XX.29, server: www.example.com, request: "GET / HTTP/1.1", 
  host: "www.example.com"
  </code></pre>
  
  <hr>
  
  <p>Just in-case, here is my complete <code>nginx.config</code> file:</p>
  
  <pre><code>#user  nobody;
  worker_processes  1;
  
  #error_log  logs/error.log;
  #error_log  logs/error.log  notice;
  #error_log  logs/error.log  info;
  
  #pid        logs/nginx.pid;
  
  
  events {
      worker_connections  1024;
  }
  
  
  http {
      passenger_root /home/deployer/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.7;
      passenger_ruby /home/deployer/.rbenv/versions/2.0.0-p247/bin/ruby;
  
      include       mime.types;
      default_type  application/octet-stream;
  
      #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
      #                  '$status $body_bytes_sent "$http_referer" '
      #                  '"$http_user_agent" "$http_x_forwarded_for"';
  
      #access_log  logs/access.log  main;
  
      sendfile        on;
      #tcp_nopush     on;
  
      #keepalive_timeout  0;
      keepalive_timeout  65;
  
      #gzip  on;
  
      server {
          listen       80;
          server_name  localhost;
  
          #charset koi8-r;
  
          #access_log  logs/host.access.log  main;
  
          location / {
              root   html;
              index  index.html index.htm;
          }
  
          #error_page  404              /404.html;
  
          # redirect server error pages to the static page /50x.html
          #
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   html;
          }
  
          # proxy the PHP scripts to Apache listening on 127.0.0.1:80
          #
          #location ~ \.php$ {
          #    proxy_pass   http://127.0.0.1;
          #}
  
          # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
          #
          #location ~ \.php$ {
          #    root           html;
          #    fastcgi_pass   127.0.0.1:9000;
          #    fastcgi_index  index.php;
          #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
          #    include        fastcgi_params;
          #}
  
          # deny access to .htaccess files, if Apache's document root
          # concurs with nginx's one
          #
          #location ~ /\.ht {
          #    deny  all;
          #}
      }
  
  
      # another virtual host using mix of IP-, name-, and port-based configuration
      #
      #server {
      #    listen       8000;
      #    listen       somename:8080;
      #    server_name  somename  alias  another.alias;
  
      #    location / {
      #        root   html;
      #        index  index.html index.htm;
      #    }
      #}
  
  
      # HTTPS server
      #
      #server {
      #    listen       443;
      #    server_name  localhost;
  
      #    ssl                  on;
      #    ssl_certificate      cert.pem;
      #    ssl_certificate_key  cert.key;
  
      #    ssl_session_timeout  5m;
  
      #    ssl_protocols  SSLv2 SSLv3 TLSv1;
      #    ssl_ciphers  HIGH:!aNULL:!MD5;
      #    ssl_prefer_server_ciphers   on;
  
      #    location / {
      #        root   html;
      #        index  index.html index.htm;
      #    }
      #}
  
      server {
        listen 80;
        server_name www.example.com;
        root /home/deployer/sites/www.example.com/public;
        passenger_enabled on;
     }
  }
  </code></pre>