I have recently deployed my Ruby on Rails application to a plain Ubuntu 16.04 DigitalOcean droplet with Nginx, passenger & Let's encrypt.
The rails app worked fine with just passenger and Nginx but after I installed Let's Encrypt, it points to the "Welcome to Nginx" page instead of my rails app.
I am able to make changes to see the "Welcome to Nginx!" page and see the results in the browser.
When I change the root location in my sites-enabled configs to my application path instead of /html I get a 403 Forbidden error.
This is where my application is: /var/www/myapp/code/
I don't know what gives... I keep getting "403 Forbidden nginx/1.14.0" when I try to change the root to my app's /public directory. I've even moved the /html
folder into myapp
directory and it loads the "Welcome to Nginx!" page there too. Is there something I need to do for it to process my index.html.erb
files in my app's views, or, do I need to make a custom index.html
without any ERB
?
I do not have an index file in my /public directory. What do I need to do for nginx to point to my
root_path
defined in my rails app's routes?The permissions are set to
root rails
for both the (working) "Welcome to Nginx!" index path and myapp/code/public path.
I would love some help, thank you!
My /etc/nginx/sites-enabled/default
(without comments):
server {
root /var/www/myapp/code/public;
index index.html.erb index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/transverseaudio.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/transverseaudio.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.transverseaudio.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = transverseaudio.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 404; # managed by Certbot
}
My /etc/nginx/sites-enabled/myapp.conf
:
server {
listen 80;
server_name transverseaudio.com www.transverseaudio.com;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/myapp/code/public;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-2.5.1/wrappers/ruby;
}
I looked further into my Ruby + Rails config and verified the right versions where installed:
Rails -v = Rails 5.2.0
Ruby -v = ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]