nginx configuration for ruby on rails application with api

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;


  ssl_certificate /etc/letsencrypt/live/;
  ssl_certificate_key  /etc/letsencrypt/live/;

  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;


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.