Application not loading in Ubuntu 18.04, NGINX, Passenger configuration - ruby-on-rails

I have installed NGINX and Passenger on Ubuntu 18.04 and am having issues getting any meaningful indication of what's wrong with my configuration.
/etc/nginx/nginx.conf
http {
# pretty much the default configuration except for this...
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-enabled/my_app (this is a symlink to sites-available)
server {
listen 80;
server_name my.app.ip.address;
root /path/to/public/folder;
passenger_enabled on;
passenger_app_root /path/to/app/root; # not public folder
passenger_ruby /home/appuser/.rvm/gems/ruby-2.0.0-p648/wrappers/ruby;
rails_env staging;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Results of systemctl status nginx
Results of passenger-status
Output of /var/log/nginx/error.log
When I try to access the IP address via a web browser, it refuses to connect and suggests I check the connection and firewall. Any thoughts on what the issue could be?

You need to remove passenger_app_root. That directive is for where passenger is, not the root of your app.
If you're using the standard RoR layout where public is a subfolder of the application root, you don't need to specify anything, but if they really are completely different than the directive you're looking for is passenger_root, which configures the root of your application.

Related

How to access my docker container without mentioning port using Host Nginx?

Here is my Nginx.conf file
Error message
Here is my nginx.conf file , also tried restart nginx,
But i can access container at this http://ipaddress:8888
server {
listen 80;
listen [::]:80;
server_name _;
#root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://18.215.189.243:8888/;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
I got this issue resolved,
the main problem was that I was using Nginx configuration in my host machine and uploading my code to the Nginx container.
I uninstalled nginx form my host machine and just using nginx container and it is working fine

Ngnix still seeing welcome screen after configuration

I have set up and deployed an application using Capistrano, Nginx, Passenger and set up the server and ngnix config file, however, I'm still seeing the Welcome to ngnix welcome screen.
Here is what I have in the /etc/nginx/sites-enabled/default file
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name IP;
passenger_enabled on;
rails_env production;
root /home/poladmin/poetry-out-loud-v2/current/public/;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
I have restarted Ngnix but I'm still not seeing the website.
Sounds like Nginx is serving you the content from it's installation directory. It's usually /usr/share/nginx but you can confirm by running:
nginx -V 2>&1 | tr ' ' '\n' | grep prefix
This will happen if it can't find a more suitable server from your configuration. Here's a few observations:
server_name IP;
This directive tells Nginx which host names to match in client requests in order to pass the request to this server. So requests to http://ip will be handled here, is that your intention?
Is your root directory really within someone's home directory structure? Fair enough...
You can lose the trailing slash from that directive, to make it:
root /home/poladmin/poetry-out-loud-v2/current/public;
but, but, what about the slash?
It lives in here:
location / {
blah blah blah...
}
You currently have no location directives apart from location = /50x.html which contains = so is an exact match only. A request for any other URL doesn't have a matching location within this server block.
try it with the folowing commands
first: service nginx configtest
to verify the Nginx functioning
second: service nginx restart

Still seeing welcome to ngnix after setup

I have set up and deployed an application using Capistrano and set up the server and ngnix config file, however, I'm still seeing the Welcome to ngnix welcome screen.
Here is what I have in the /etc/nginx/sites-enabled/default file
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name IP;
passenger_enabled on;
rails_env production;
root /home/poladmin/poetry-out-loud-v2/current/public/;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
But as I said when I go to the server IP all I see is
Since you edited /etc/nginx/sites-enabled/default file, try to reload nginx with nginx -s reload command (if you are using Linux, or similar depending on your operating system and nginx version).
As you have edited the nginx config file you can try to restart nginx by doing sudo /etc/init.d/nginx restartto make the config file take effort. Also do not forget to start the real ruby server and make sure it is listening to the same port you configured through nginx.(some times the ruby app may be running on a different port)

Deployed Rails app still seeing nginx splash page

I've just set up my first Digital Ocean VPS and managed to deploy my Rails app by following this guide: https://gorails.com/deploy/ubuntu/14.04
Unfortunatley I am still seeing the nginx splash page and hoep you guys can help me fix this?
In the nginx error log I am seeing this:
[ 2016-04-20 14:48:15.4541 31875/7f70762f57c0 age/Ust/UstRouterMain.cpp:342 ]: Passenger UstRouter online, PID 31875
2016/04/21 14:58:58 [emerg] 1721#0: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default.save:27
My nginx conf looks like:
server {
listen 80 default_server;
server_name dev.myapp.co.uk;
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 = /50x.html {
root html;
}
}
I obviously have changed "myapp" to my correct domain and app name as appropriate.
Any ideas?
The issue seems like you are having two nginx configuration files inside /etc/nginx/sites-enabled/ and both of them have the same listen 80 default_server; line.

Deploying Frontend and Backend separately for Rails on same server

We have made a rails app with foundation framework for frontend and using rails api for backend. In development environment, I was using apache2 for frontend and webrick for backend. So, I was sending all json requests to localhost:3000.
On production environment, I have already deployed the frontend using apache2 and was trying to deploy backend with nginx and passenger but they both use the same port. Can anyone suggest a solution to this. Ideally, I want a URL similar to my localhost (like 104.xx.xx.xx:3031) on production.
You can run nginix on diff port
Try this
#server config
server {
listen 8083;
server_name localhost;
location / {
root /var/www/project_path/;
passenger_enabled on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Put this in nginx config file

Resources