First off, apologies: I know the 403 Forbidden question is a common one for Rails/Nginx installs, but none of the answers I've read so far have solved it for me.
Disclaimer: This is my first time deploying a Rails app somewhere that isn't Heroku. Please be gentle. ;)
Situation: I have a Rails app running on an Ubuntu 12.04 server, running Nginx (installed with Passenger).
I've deployed my app to my server correctly, but when I attempt to access the site, I receive a 403 Forbidden error.
Checking my error logs, I see:
2013/10/23 22:47:01 [error] 27954#0: *105 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 50.3…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
2013/10/23 22:47:10 [error] 27954#0: *106 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 184…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
2013/10/23 22:47:12 [error] 27954#0: *107 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 151…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
However, when checking permissions on this directory, I see that the user I have setup to use Nginx had both read and execute permissions on it.
Here's the relevant info from my nginx.conf:
user XXXX;
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/cole/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.21;
passenger_ruby /home/cole/.rvm/wrappers/ruby-2.0.0-p247/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 colepeters.com www.colepeters.com;
passenger_enabled on;
root /var/www/colepeters.com/current/public/;
rails_env production;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/colepeters.com/current/public;
index index.html index.htm;
# autoindex on;
}
I would greatly appreciate any help on resolving this. Thanks!
UPDATE I have since corrected the erroneus passenger_ruby path, but the 403 Forbidden is persisting, even after restarting Nginx.
I was running a similar setup to yours and having the same problem with my nginx.conf file. Stumbling across the Nginx pitfalls page helped me solve it.
Your file looks similar to mine, so I'll share two things you may want to try that worked for me:
first, you have the
root
path in both theserver {}
block AND thelocation {}
block. While not necessarily a problem, according to the docs linked above "If you add a root to every location block then a location block that isn't matched will have no root." I got rid of the roots in the location blocks but kept it in the server block.move the 'index' directives (
index index.html index.htm;
) out of the location block up to within thehttp {}
block. The location blocks will inherit from this.doing those two things and restarting the server worked for me.
The problem lies in the
location / {...}
section: thepassenger_enabled on
doesn't propagate from theserver {...}
into thelocation / {...}
.If you either remove
location / {...}
, or addpassenger_enabled on
to it, it should work.