Report this

What is the reason for this report?

How to set up rails app with Nginx/Capistrano

Posted on May 22, 2021

Hi all, sorry for this stupid question but I don’t know how to figure out this issue. I can’t run my app after changed SSL to certbot.

My NGINX config: /etc/nginx/conf.d/airstage.co.conf (it was chenged by certbot)

server {
    server_name airstage.co www.airstage.co;
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/airstage.co/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/airstage.co/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.airstage.co) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    if ($host = airstage.co) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name airstage.co www.airstage.co;
    return 404; # managed by Certbot
}

And here /etc/nginx/sites-available/default

upstream app {
  server unix:///home/deploy/airstage_web/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
        root /home/deploy/airstage_web/current/public;
        try_files $uri/index.html $uri @app;
        location /home/deploy/airstage_web/current/public {
          autoindex on;
          autoindex_exact_size off;
        }
        location @app {
                        proxy_pass http://app;
                proxy_set_header X-Forwarded-Proto https;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_buffer_size 128k;
                proxy_buffers 4 256k;
                proxy_busy_buffers_size 256k;
        }
        location ^~ /assets/ {
                gzip_static on;
                expires max;
                add_header Cache-Control public;
        }
        error_page 500 502 503 504 /500.html;
        client_max_body_size 1G;
        keepalive_timeout 10;
}

This all returned me Welcome to nginx! page or if I moved root path nginx/conf.d/airstage.co.conf

[error] 14714#14714: *763 directory index of "/home/deploy/airstage_web/current/public/" is forbidden, client: My_IP, server: airstage.co, request: "GET / HTTP/1.1", host: "www.airstage.co"

My web server is (include version): nginx/1.10.3 (Ubuntu)

The operating system my web server runs on is (include version): Ubuntu 16.04

Domain: GoDaddy.



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.

Heya,

The error message you provided, “directory index of ‘…’ is forbidden,” suggests that NGINX is trying to list the contents of the directory but doesn’t have permission to do so. To resolve this issue and get your app running with SSL certificates obtained via Certbot, you need to make sure that your NGINX configuration is set up correctly.

Make sure that the NGINX process has the necessary permissions to access your application’s files and directories. The user running NGINX (often www-data on Ubuntu) should have read and execute permissions on your application directory.

You can change the owner and group of your application directory if needed:

  1. sudo chown -R www-data:www-data /home/deploy/airstage_web

On another note - 1. Directory Index Forbidden Error: The error message indicates that directory indexing is not allowed, and NGINX is trying to list the contents of the directory. To resolve this, ensure that your NGINX configuration points to the correct root directory for your application.

In your NGINX server block for the website (/etc/nginx/sites-available/default), the root directive should point to your application’s public directory:

  1. root /home/deploy/airstage_web/current/public;

Verify that this path is correct and that your application is located in the specified directory.

Reload NGINX: After making changes to your NGINX configuration, you need to reload NGINX to apply the changes:

  1. sudo systemctl reload nginx

If the issue persists, check your NGINX error log for any further details on what might be causing the problem. You can view the NGINX error log using:

  1. sudo tail -f /var/log/nginx/error.log

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.