Report this

What is the reason for this report?

nginx configuration for ruby on rails application with api

Posted on May 10, 2021

I have hosted my ROR application on digital ocean using ubuntu droplet, my application is using nginx, passenger. Application web pages are working as expected but there are few api’s that are created in the same application which are giving 403 forbidden when pining the api from react mobile app.

“Completed 403 Forbidden in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms | Allocations: 309)”

I am guessing this is something to do with my nginx configuration can somebody please help.

nginx conf file

server {
  listen 443 ssl;

  server_name net2fit.com;

  ssl_certificate /etc/letsencrypt/live/net2fit.com/fullchain.pem;
  ssl_certificate_key  /etc/letsencrypt/live/net2fit.com/privkey.pem;

  root /home/deploy/net2fit/public;

  passenger_enabled on;
  passenger_ruby /home/deploy/.rbenv/versions/2.6.6/bin/ruby;
  passenger_app_env production;

  access_log /var/log/nginx/app.access.log;
  error_log /var/log/nginx/app.error.log;

  location /cable {
    passenger_app_group_name net2fit_websocket;
    passenger_force_max_concurrent_requests_per_process 0;
  }

  location /api/v1/ {
    passenger_enabled on;
    rails_env production;
    root /home/deploy/net2fit/public;
    error_page 500 502 503 504 /50x.html;
  }

  #Allow uploads up to 100MB in size
  client_max_body_size 100m;

  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  }

        # this rewrites all the requests to the maintenance.html
        # page if it exists in the doc root. This is for capistrano's
        # disable web task
        if (-f $document_root/system/maintenance.html)
        {
          rewrite  ^(.*)$  /system/maintenance.html last;
          break;
        }

}


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 @DriftingBlueAxolotl,

On a first glance, everything seems to be okay with Nginx. I do have a couple of questions, does all API calls are being called with – /api/v1/?

Everything else does seem okay so it’s possible the issue is not with Nginx as well but somewhere entirely different.

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.