403 error with nginx + passenger + rails 3 - ruby-on-rails

I have simple application which works well on Apache but gives me error 403 after moving to Nginx.
Here is my configuration:
server {
server_name myapp.com;
access_log off;
root /home/www/myapp/public;
autoindex on;
passenger_enabled on;
rails_env production;
}
Nginx is running from www-data user which has r+x permissions to all the folders on the path to the application.
Nginx is 0.8.54 and Passenver is 3.0.5.
Any ideas what can be wrong?
Obviously no reasonable errors in nginx log file (I increased logging level to maximum) and also nothing in rails log files.

You're missing the http port:
server {
listen 80;
...
}

Related

passenger wont find public path

I'm trying to setup my rails server and passenger wont recognize my app giving this error on log:
[error] 1473#1473: *1 "/home/myapp/public/index.html" is not found (2: No such file or directory)
or a 404 error in client.
i've done all troubleshooting possiilities to resolve but nothing.
here is my server block:
server {
listen 80;
server_name mydomaiin.com;
rails_env development;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/myapp/.rbenv/versions/2.4.0/bin/ruby;
# Tell Nginx and Passenger where your app's 'public' directory is
root /home/myapp/public;
}
can anyone help me?
thanks
As your root dir is in /home/myapp/myapp, update your server conf:
server {
listen 80;
server_name mydomaiin.com;
rails_env development;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/myapp/.rbenv/versions/2.4.0/bin/ruby;
# Tell Nginx and Passenger where your app's 'public' directory is
root /home/myapp/myapp/public;
}

cannot assess rails app on amazon ec2

I'm using Amazon EC2 and tried to deploy a rails project.
I have install nginx/passenger and successfully made nginx server run.
I started my rails project with name "forfun"
then I set the root of nginx to /home/ubuntu/rails/forfun/public
I initialized a file named "index.html", then I could see the page in browser
(http://[my ip]:80)
However, what i really wanna see is the welcome page of rails app.
I tried do remove index.html and see what i got. I saw 404 Forbidden error.
/var/log/nginx/error.log reveals that directory index of "/home/ubuntu/rails/forfun/public/" is forbidden
What step i actually missed?
by the way, do i need to do "rails server" while nginx is running?
ps:
(1) /opt/nginx/conf/nginx.conf
http {
passenger_root /usr/local/rvm/gems/ruby-2.3.0/gems/passenger-5.0.26;
passenger_ruby /usr/local/rvm/gems/ruby-2.3.0/wrappers/ruby;
...
server {
listen 80;
server_name 52.196.XX.XXX;#my amazon public ip
root /home/ubuntu/rails/forfuni/public;
}
(2)/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/ubuntu/rails/forfun/public;
index index.html index.htm;
}
Try adding /etc/nginx/sites-enabled/default
server {
listen 80 default_server;
server_name 52.196.XX.XXX;#my amazon public ip;
passenger_enabled on;
passenger_app_env development; #or whatever rails env you want.
The whole process of deploying a rails app using nginx/passenger is documented here. See the nginx section.
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04

Running multiple rails app using passenger

I am hosting a Rails app using passenger and nginx.
I have an nginx.conf with a working server block for the first app that looks somewhat like this.
server {
listen 80;
server_name app1.example.com www.app1.example.com;
passenger_enabled on;
root /home/ec2-user/app1/public;
}
However, I want to deploy a second rails app and on the same nignx.conf wrote:
server {
listen 80;
server_name app2.example.com www.app2.example.com;
passenger_enabled on;
root /home/ec2-user/app2/public;
}
I think there is a conflict with the the ports but I am having trouble finding answers to solving this.

Nginx not detecting the root location from config for Rails 3.2 app

Here is the error.log of nginx server running on ubuntu 12.04.
2014/03/17 12:47:17 [error] 7939#0: *1 open() "/opt/nginx/html/mkl/authentify/signin" failed (2: No such file or directory), client: xxx.xxx.228.66, server: xxx.xxx.109.181, request: "GET /mkl/authentify/signin HTTP/1.1", host: "xxx.xxx.109.181"
In /opt/nginx/conf/nginx.conf, it is configured as following (the only server block in conf):
server {
listen 80;
server_name xxx.xxx.109.181;
root /ebs/www/;
passenger_enabled on;
rails_env production;
passenger_base_uri /mkl;
.....
}
The root of nginx server is pointing to /ebs/www/. However the nginx is accessing the /opt/nginx and throws out no such file error. What causes the problem? Thanks.
The nginx was installed with passenger-install-nginx-module after gem passenger was installed.
Correctly root is your public order from your application:
server {
listen 80;
server_name xxx.xxx.109.181;
root /ebs/www/YOUR_APPLICATION/current/public;
# e.g. root /var/www/vhosts/example.com/httpdocs/example/current/public;
passenger_enabled on;
rails_env production;
passenger_base_uri /mkl;
.....
}
The problem is fixed after adding one more server {} block after the first (only) server block in nginx.conf. In previous version (probably 1.4.x), there were 2 server blocks in nginx.conf. In current version, there is only one server {} block.
More reading about the solution can be found at Why is nginx responding to any domain name? & https://serverfault.com/questions/416064/rails-application-only-showing-nginx-default-page

How to add a second app to Phusion Passenger?

I have my Phusion Passenger Nginx configured to as below :
server {
listen 80;
server_name blog.abc.com;
passenger_enabled on;
root /app/public;
}
Im about to host the main site abc.com also in this machine. How can I do that (Its a separate app)? Is it possible to add another server block like this :
server {
listen 80;
server_name abc.com;
passenger_enabled on;
root /app2/public;
}
Phusion Passenger author here. Yes. Just add another virtual host block for the other app. It works exactly as expected.
I configured my second app on sub-uri of first app. Below is the nginx conf and settings what i done.
nginx.conf:
server {
listen 80;
server_name localhost;
location / {
root /var/www/demo/public;
passenger_enabled on;
rails_env production;
}
location /test {
root /var/www/demo;
passenger_base_uri /test;
passenger_enabled on;
}
Then add symbolic link:
ln -s /var/www/logger/public /var/www/demo/test

Resources