Nginx - passanger displays 404 not found for rails controllers - ruby-on-rails

This is my first rails app i am deploying to a server other than heroku.I deployed my rails app to digitalocean successfuly. When i type the ipaddress in browser, home page shows up. But when i try to redirect to other controllers like xxx.xxx.xxx.xx/users/sign_in it show 404 Not Found. Also none of the images are showing up.
/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name mydomain.com;
passenger_enabled on;
rails_env production;
root /home/deploy/myapp/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = / {
passenger_enabled on; <-added this line for home page to show up
}
location = /users/sign_in {
passenger_enabled on; <-added this line for sign_in view to show up
}
}
I dont know what i am missing. do I have to add passenger_enabled on; to each location?or is there a common configuration for all the uri's of the application?

I fixed it. Removed all location and added passenger_enabled on; outside.

Related

Nginx 403: directory index of "/home/deploy/MyApp/current/public/" is forbidden

I have set up a rails project with nginx and passenger. I'm getting a 403 when trying to access the site. This is my config file at /etc/nginx/sites-enabled/mysite.com:
server {
listen 80;
server_name www.mysite.com *.mysite.com;
passenger_enabled on;
rails_env production;
root /home/deploy/mysite/current/public;
index index.html index.htm;
#try_files $uri;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ /index.html;
}
location = /50x.html {
root html;
}
}
My passenger_root and passenger_ruby are correctly set in nginx.conf and I have set write/read permissions on the app's root/, root/current and root/current/public folders for the nginx user.
Any ideas? Thx in advance.
You need to specify these two options as well
passenger_root /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p290/ruby;
You can check the path of your passenger installation with
passenger-config --root
And Ruby version with
which ruby
compare these outputs with what you specify.

grape api with subdomain does not work on my nginx server

I have myapp.com for my main app, and api.myapp.com for api. Everything works fine and dandy at local development that's been serve with pow, however when I try to test on my nginx server api.myapp.com/v1/products/1 gives me a 404. (api.myapp.com redirects to myapp.com which is expected due to DNS setup)
I'm using, passenger+nginx, rails and grape-api, here are my setup:
routes.rb
constraints subdomain: 'api' do
mount API::Base, at: '/'
end
nginx conf
server {
listen 80;
listen [::]:80;
server_name myapp.com www.myapp.com api.myapp.com;
passenger_enabled on;
rails_env production;
root /path/to/myapp.com;
error_page 500 502 503 504 /50x.html;
location /50x.html {
root html;
}
}
I have CNAME *.myapp pointing to myapp.com.
I'd probably overlooked something that's fairly basic and fundamental, can someone point me to the right direction. Much appreciated.
Add 2 server blocks..
server {
listen 80 default_server;
server_name app.com;
...
}
server {
listen 80;
server_name subdomain.app.com;
...
}

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

Nginx for multiple apps with different subdomain

Been trying to search for a time but can't seem to find a solution. I want to set multiple apps in one server via nginx. Current nginx.conf is as follows:
server {
listen 80;
server_name mydomain.co;
root /mydomain/current/public;
passenger_enabled on;
rails_env production;
}
server {
listen 80;
server_name testing.mydomain.co;
root /mydomain-test/current/public;
passenger_enabled on;
rails_env test;
}
It serves up the correct environment (test) but doesn't serve the correct codebase. I checked the directory mydomain-test via ssh and it contains the recent code but is not being served by nginx.
Basically, what I want is:
mydomain.co to serve /mydomain/current/public
testing.mydomain.co to serve /mydomain/current/public
How is this done correctly?
I believe the root directive should be in the location section. I am unsure of the rails directive and passenger_enabled directive but the rest is similar to what I use and works. Might be best to also specify the index script (i have it set to index.php but change as appropriate).
Once you have made the changes be sure to restart nginx.
server {
listen 80;
server_name mydomain.co;
location / {
root /mydomain/current/public;
index index.php;
}
passenger_enabled on;
rails_env production;
}
server {
listen 80;
server_name testing.mydomain.co;
location / {
root /mydomain-test/current/public;
index index.php;
}
passenger_enabled on;
rails_env test;
}

Multiple Ruby apps (Rails and Sinatra) deployed using Passenger for Nginx?

I have two Ruby applications, one is under Rails and the another is under Sinatra.
How can I deploy both these apps in Nginx and Passenger with one in the root ("localhost:3000") and the other in subroot ("localhost:3000/test")?
The Rails application is running with this configuration. Everything seems to work OK:
server {
listen 80;
server_name localhost;
location / {
root /var/www/demo/public;
passenger_enabled on;
rails_env production;
}
location /test/ {
root /var/www/test/public;
passenger_base_uri /test/;
proxy_pass http://10.0.3.12:80/test/;
passenger_enabled on;
}
I am not able to access the second application.
The server returns 404 for the second app and the first app is still running.
I believe you need to define local servers, that only listen on local port and define your passenger apps there. Your actual server listening on port should only act as proxy.
server {
listen localhost:8181;
server_name test_app;
root /var/www/test/public;
passenger_enabled on;
}
server {
listen localhost:8182;
server_name demo_app;
root /var/www/demo/public;
passenger_enabled on;
rails_env production;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8182/;
}
location /test/ {
proxy_pass http://localhost:8181/;
}
}
I didn't have chance to test this config, so it might have some minor flaws, but it should be correct in high-level terms.
In nginx.conf:
server {
listen 80;
server_name localhost;
location / {
root /var/www/new/public;
passenger_enabled on;
rails_env production;
}
location /test {
root /var/www/demo;
passenger_base_uri /test;
passenger_enabled on;
}
Add a soft link:
ln -s /var/www/loggerapp/public /var/www/new/test

Resources