While I was building my virtual petsite I followed the following articles listed below to setup my new web server. https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04#step-1-installing-certbot https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04 https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-22-04 https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-22-04#option-2-installing-node-js-with-apt-using-a-nodesource-ppa https://docs.digitalocean.com/products/droplets/how-to/tag/ https://www.writesoftwarewell.com/how-http-cookies-work-rails/ https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-22-04 https://www.digitalocean.com/community/tutorials/how-to-use-postgresql-with-your-ruby-on-rails-application-on-ubuntu-20-04
These articles worked really well, and I have both Ruby on Rails and Nginx active. The problem is that I am having a difficulty in getting Ruby on Rails to be displayed on https://dev.duelingpets.net.
Instead of the Ruby on Rails file, I am getting this index file from Nginx to be displayed: Success! The Duelingpets server block is working!
My current config for the nginx looks like this:
server {
root /var/www/duelingpets.net/html;
index index.html index.htm index.nginx-debian.html;
server_name duelingpets.net dev.duelingpets.net;
location / {
try_files $uri $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/duelingpets.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/duelingpets.net/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 = dev.duelingpets.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = duelingpets.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name duelingpets.net dev.duelingpets.net;
return 404; # managed by Certbot
}
duelingpets@DuelingpetsWS1:/etc/nginx/sites-available
When I try to change the root file from root /var/www/duelingpets.net/html;
to root /var/www/duelingpets.net/html/Duelingpets/public
, I get: 403 Forbidden:
nginx/1.24.0 (Ubuntu) Message to pop up.
I checked the permissions and they appear to be in working order. I want it to point to my Ruby on Rails website on dev.duelingpets.net but I can’t figure out how to do so. I also heard that Passenger is obsolete with the newer versions of Nginx so I was wonder what to use to get the Rails website to display in the browser?
Any advice would be greatly appreciated on how to get this to work.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
Currently, your website seems to be up and running, can you confirm if this is also the case on your side as well?
Besides that, configuring Nginx to serve a Ruby on Rails application can be a bit tricky, especially when transitioning from development to production environments. Your scenario indicates that Nginx is correctly installed and serving static files, but it’s not properly configured to serve your Rails application.
Here are a few things that you can check:
error.log
(it is usually found in/var/log/nginx/error.log
) can provide insights. Passenger’s logs can also be helpful.sudo systemctl restart nginx
).nginx -t
to check your Nginx configuration for syntax errors.Feel free to share the errors here!
Besides that, here are a few more things that I would recommend checking:
1. Verify Passenger Installation
Even though you’ve heard Passenger might be obsolete with newer versions of Nginx, it’s still a viable and popular option for deploying Ruby on Rails applications. First, ensure that Passenger is installed and integrated with Nginx.
passenger-config validate-install
andpassenger-config about nginx-module
.2. Configure Nginx with Passenger
Modify your Nginx configuration to use Passenger. Here’s a simplified version of what your server block might look like:
3. Permissions and Ownership
The 403 Forbidden error when changing the root directory often points to a permissions issue. Ensure that the user running Nginx (often
www-data
) has read access to the/var/www/duelingpets.net/html/Duelingpets/public
directory and all its parents.chmod
andchown
to adjust permissions and ownership if necessary.ls -l /var/www/duelingpets.net/html/Duelingpets
and ensure that directories have at least755
and files have644
.Let me know how it goes!
Best,
Bobby
Heya @ebeecroft,
If I’m not mistaken, the APP with Ruby on Rails runs on a specific port, is that correct?
Configuring Nginx as a reverse proxy for a Ruby on Rails application is a common and recommended setup, especially in production environments.
Here is an example config:
Considerations
Environment: The specifics of your Nginx configuration can vary based on your server environment, domain setup, and specific requirements of your Rails application.
SSL Configuration: If you are serving your application over HTTPS, you will need to include SSL configuration in your Nginx setup.
Rails Server Configuration: Ensure your Rails server (like Puma or Unicorn) is configured correctly to work with Nginx as a reverse proxy.
Testing: After configuration, thoroughly test your application to ensure that everything works as expected, especially the routing, static assets, and any websockets or long-polling features.
Using Nginx as a reverse proxy for Ruby on Rails can significantly enhance the performance, scalability, and security of your application, making it a worthwhile setup for most production environments.
Heya @ebeecroft,
I’m starting this new thread as the other was too long and couldn’t be followed anymore.
As for the errors you’ve received:
It seems like your permissions and ownership might be wrong. Try to set the permissions of your folders to 755 and of files to 644.
Additionally, regarding not being able to load your Ruby on Rails app via your Droplet’s IP
See if you’ve allowed the App to be accessed by your Droplet’s IP address.