casraf
casraf

Reputation: 21694

"Access Forbidden" - Passenger, Nginx, Rails

I know there are about 100 questions about this, but after hours of research, I couldn't find my solution. Here's my nginx config:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/LucyRb/public;
    passenger_enabled on;
    passenger_app_env production;

    index index.html index.htm;
    server_name <domain name>;

    location / {
            try_files $uri $uri/ /index.html;
            passenger_enabled on;
    }
}

My /public directiory:

root@Lucy:/var/www/LucyRb/public# namei -l *
f: 404.html
-rwxrwxrwx root root 404.html
f: 422.html
-rwxrwxrwx root root 422.html
f: 500.html
-rwxrwxrwx root root 500.html
f: favicon.ico
-rwxrwxrwx root root favicon.ico
f: robots.txt
-rwxrwxrwx root root robots.txt

I don't think it's a permission problem. I've already run rake db:migrate to create the database, and it worked. I'm pretty sure environments are set up properly. All I get is a file listing (since autoindex is on, otherwise I get a 403). But routes, nor does the app default index/root, work. I've read the Passenger documentation, and I tried troubleshooting with the docs and other SO questions, but I can't seem to get this working.

I haven't forgotten to bundle install and all the proper packages are installed, I'm pretty sure (did I forget any? mysql, rvm and its relevant steps for installing rails, nginx, passenger... Probably another 2-3).

I know I'm not supposed to start rails server because it will only allow 1 connection at a time. So nginx is supposed to do that properly, right? Or is that what I'm supposed to do with certain flags?

Thanks in advance.

Upvotes: 3

Views: 890

Answers (8)

casraf
casraf

Reputation: 21694

Okay everyone. With the assistance of Passenger's author on their IRC channel, I was able to resolve the problem.

I had passenger installed twice.

From articles I followed that didn't cover the topic thoroughly enough, I was under the assumption Passenger is an installable module of Nginx, which caused me to install Nginx with apt-get, and Passenger via the gems.

This is an unnecessary redundancy and causes conflicts.

Either use only apt-get or only the gems in these cases.

passenger-install-nginx-module not only installs a module, it also compiles Nginx from scratch, simply because Nginx is not a modulable application. It is either compiled alongside the module, or doesn't have one at all.

To sum it up:

  1. Only use one method to install Nginx && passenger.
  2. Make sure the config points to the right files.
    I also had a problem with the paths to ruby. Make sure it points to the wrapper, and not the executable alone:

    root@Lucy:/usr/local/rvm# which ruby
    /usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby
    

    In your config:

    passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p353/ruby;
    

Upvotes: 1

Dogweather
Dogweather

Reputation: 16779

Every time I've received that error it's been because Nginx wasn't correctly pointing to the passenger gem and executable. Here's what I suggest, to get things working:

  1. Uninstall and/or shut down whatever nginx you've currently got installed.
  2. cd into your app's root directory,
  3. execute the command: passenger-install-nginx-module and let passenger download, compile, and install nginx in /opt.
  4. use the sample config provided by the passenger script for /opt/nginx/conf/nginx.conf.
  5. To get the server to start on boot, just add the one line /opt/nginx/sbin/nginx to your /etc/rc.local script.

This recipe has been repeatable and foolproof for me running RVM + Ruby 1.9, 2.0, and Rails 3 and 4 on Ubuntu 10 and 12.

Upvotes: 0

Alejandro Alcalde
Alejandro Alcalde

Reputation: 6220

Have you tried to change your files to www-data user?

Upvotes: 0

S.Spencer
S.Spencer

Reputation: 611

You have

# nginx config
root /home/LucyRb/public;

# shell
/var/www/LucyRb/public

Do you have a correct app in /home/LucyRb? If so, what is the relevance of /var/www/LucyRb? If this is a mistake in your config, then it if probably going to cause some trouble!

Upvotes: 0

Jim
Jim

Reputation: 1568

I was going to place this in my comments section but space and formatting are limited so:

I also see you're specifying passenger_enabled twice, which seems unnecessary. I've never seen it turned on in a location directive before, but that might not be your problem.

What do your logs say? You don't seem to have passenger logging/debugging turned on (in http directive):

http {
...
    passenger_debug_log_file '/path/to/passenger_debug.log';
    passenger_log_level       5; # default
}

Another thing I'm noticing from your post is that your public directory doesn't seem to contain a rails application??

Upvotes: 0

Jim
Jim

Reputation: 1568

Assuming your config.ru is in your specified passenger_app_root, try removing your location / {...} directive, restart nginx, and see if your app at least starts up. I'm not saying this is the fix, but a troubleshooting measure.

Upvotes: 0

moosilauke18
moosilauke18

Reputation: 931

How did you install passenger? With RVM? RVMSUDO or sudo? Chances are you shouldn't be using your app as root. So the permissions on the files aren't allowing passenger to use the rails app.

Upvotes: 0

junil
junil

Reputation: 768

Suggestion- Try moving your app to someplace that is accessible by normal user.for example home directory

Upvotes: 0

Related Questions