How to configure nginx with passenger with rails application - ruby-on-rails

I have followed this tutorial https://www.digitalocean.com/community/articles/how-to-install-rails-and-nginx-with-passenger-on-ubuntu
I have installed passenger with nginx on my virtual machine and trying to access the site.
In the root I have specified path as root /var/rails_apps/public/; which give me Welcome to Nginx page,
server{
listen 80;
server_name localhost;
root /var/rails_apps/public/;
passenger_enabled on;
}
As my root page of my site is in the /var/rails_apps/app/views/home/index.html.erb
so I changed the path to root /var/rails_apps/app/views/home/;
server{
listen 80;
server_name localhost;
root /var/rails_apps/app/views/home/;
passenger_enabled on;
}
but still for both root I am getting Welcome to Nginx page.
My request URL is like this -> /#{IpAddressOfVirtualMachine}:80/
When I specified different port for listening eg 1027 then it gives me error Unable to connect
Please explain how I can get my site running using nginx and passenger, is there any other setting required?

I am able run my site just did following changes.
Install nginx init script
nginx init script by Jason Giedymin helps us to administer web server easily.
$ cd
$ git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git
$ sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx
$ sudo chown root:root /etc/init.d/nginx
After that rails g controller pages home
And point root to public folder root /var/rails_apps/helloworld/public;
then access my virtual machine through http #{IpAddressOfVirtualMachine}:1027/pages/home
port 80 was busy so I used different which is port 1027
And it works !!!
you can refer this blog for more information
http://ershadk.com/blog/2012/04/05/set-up-rails-3-2-2-with-passenger-rvm-and-ngnix/

Change the root back to public folder, and open the URL without the port number

You need to change the server name in the nginx config to the same IP you are connecting to, and yes keep the root in the public folder, that's how rails work.
server_name 123.456.789.000; # replace with your IP
Instead of localhost, then restart nginx.

Related

Can't configure nginx reverse proxy

I'm running php+nginx api inside docker container. It is available on port 8080. I trying to add nginx reverse proxy to open api on address api.versite.online and frontend project on versite.online.
I installed nginx on server, added /etc/nginx/sites-available/api.versite.online config (also added symlink to sites-enabled directory), tested config with nginx -t, restarted nginx service with systemctl reload nginx, but it had no effect. api.versite.online:8080 and versite.online:8080 makes request to docker container, looks like top level nginx are ignored.
Nginx access log is empty.
/etc/nginx/sites-available/api.versite.online config
server {
listen 80;
server_name api.versite.online;
access_log /var/log/nginx/api.versite.access.log;
location / {
proxy_pass http://localhost:8080;
}
}
It seems that i forgot to add a firewall rule with sudo ufw allow 'Nginx HTTP'

directory index of "..." is forbidden

I am trying to get phusion passenger and nginx running on Mac OSX. It has been very difficult.
I followed the instructions here exactly.
$ brew install nginx --with-passenger
$ brew info nginx --with-passenger
Then it tells me this:
To activate Phusion Passenger, add this to
/usr/local/etc/nginx/nginx.conf, inside the 'http' context:
passenger_root /usr/local/opt/passenger/libexec/src/ruby_supportlib/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
What's interesting about that is that is not the ruby my site uses. I use rvm and have generated a .versions.conf file:
rvm --create --versions-conf use ruby-2.1.2#core
Hence, when you cd to my root folder of site, you get the following:
$ rvm-prompt
ruby-2.1.2#core
So that is what I added to nginx.conf:
http {
...
passenger_root /usr/local/opt/passenger/libexec/src/ruby_supportlib/phusion_passenger/locations.ini;
passenger_ruby /Users/dviglione/.rvm/gems/ruby-2.1.2#core/wrappers/ruby;
Note that when I run passenger-config, it does give me a different location for locations.ini:
$ /usr/local/bin/passenger-config --root
/usr/local/Cellar/passenger/5.0.26/libexec/src/ruby_supportlib/phusion_passenger/locations.ini
I don't know which location is correct but I stuck with the one that it provided during the install. If I changed to the other location, I get a different issue: "This site can't be reached".
In nginx.conf, my server block looks like this:
server {
rack_env development;
listen 8080;
server_name mysite_development;
root /Users/myuser/projects/core;
access_log /Users/myuser/projects/core/log/nginx_access.log;
error_log /Users/myuser/projects/core/log/nginx_error.log;
passenger_enabled on;
}
I added the following to /etc/hosts:
127.0.0.1 mysite_development
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
The root directory has the following permissions:
$ ls -ld core
drwxr-xr-x 37 myuser CORP\Domain Users 1258 Oct 14 18:45 core
Yet, when I navigate to http://mysite_development:8080/, I get the following error in my nginx error log:
2016/10/14 18:52:23 [error] 90766#0: *1 directory index of
"/Users/myuser/projects/core/" is forbidden, client: 127.0.0.1,
server: mysite_development, request: "GET / HTTP/1.1", host:
"mysite_development:8080"
The problem is not with nginx itself because I created a test folder and put an index.html in there and then created a server block for that and the index.html successfully displayed in browser. So problem is either with Passenger or Rails.
Note if I add this to the server block:
location / {
root html;
index index.html index.htm;
}
Then I just get the 'Welcome to nginx!' page.
I even chmod 777 recursively on the entire directory and its files of the Rails app. Still get the 403 Forbidden error. It has to be a problem with Passenger.
How can I resolve this?
You need to explicitly specify, where actual Ruby code of a Rails application is located, using passenger_app_root directive, described in Passenger's documentaion.
More details in my full answer.

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

NGINX Setup (Rails App in a subdirectory)

I'm using NGINX with Passenger to run a rails application on an Ubuntu server.
However, I'd like to have the rails app served from www.mydomain.com/store , and have
a wordpress install served from www.mydomain.com.
How would one go about setting up the nginx.conf?
From the official manual:
To do this, make a symlink from your Ruby on Rails application’s public folder to a directory in the document root. For example:
ln -s /webapps/mycook/public /websites/phusion/rails
Next, set passenger_enabled on and add a passenger_base_uri option to the server block:
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on; # <--- These lines have
passenger_base_uri /rails; # <--- been added.
}

Nginx and Passenger deploy issue

Currently I can only get the default nginx page to come up on my domain name. I am pretty sure the error is either in the /etc/hosts file or the enginx.config file.
my /etc/hosts file is
127.0.0.1 localhost.localdomain localhost
myip server.mydomain.com server
and nginx.config is:
server {
listen 80;
server_name server.mydomain.com;
root /whatever/pulic;
passenger_enabled on;
rails_env production;
I don't get any errors in the log. Incidentally I can run mongrel and on mydomain:3000 see the application there.
In your /etc/hosts, you have
123.45.67.78 server.domain.com servername
So in you nginx.conf you should have the line
server_name servername
as you defined in the third column of your /etc/host. Make sure you don't still have the default nginx server block in your nginx.conf file, too, otherwise it might be taking priority (based on it's relative position).
We just had this issue. The problem turned out to be that Nginx was using a different config file than we thought it was (possibly an issue with how it was compiled on the server?).
We discovered this by doing nginx -t, which lists the config file it's reading and tests the syntax. The one it said it was testing was not the one we expected.

Resources