Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

547
Views
Heroku - Seperate frontend and backend with Nginx on same domain

I have an application with two github repos one for react and one for rails app. Requirement is all the routes should go to Rails server except routes starting with /catalog should go to to React app. Rails app server will communicate with React Server internally. SSL is configured on Nginx level.

I have created 3 different apps in heroku :

  • Rails server app
  • React server app
  • Web Server(Nginx)

My nginx server config looks like :

upstream rails {
  server $HEROKU_APP_rails_URL;
}

upstream react {
  server $HEROKU_APP_react_URL;
}


server {
  listen $PORT;
  server_name *.xyz.com;
  # large_client_header_buffers 4 32k;

  location / {
    proxy_set_header    Host $host;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass          http://rails;
  }

  location /catalog {
    
    proxy_set_header    Host $host;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass          http://react;
  }
}

with above config I am getting HTTP 400 error on Nginx and it is not able to redirect the request. Please let me know what am i doing wrong.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Finally managed to solve this issue.. My nginx config looks like

  upstream upstream_app_a {
        server app_a.herokuapp.com:443;
    }

    upstream upstream_app_b {
        server app_b.herokuapp.com:443;
    }

    server {
    
        listen $PORT;

        location / {
            set $upstream upstream_app_a;
            proxy_pass https://$upstream;
            proxy_ssl_name app_a.herokuapp.com;
            proxy_set_header x-forwarded-host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host app_a.herokuapp.com;
            
        } 
        location /static {
            set $upstream upstream_app_b;
            proxy_pass https://$upstream/static;
            proxy_set_header        Host app_b.herokuapp.com;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        X-Forwarded-Proto $scheme;
          
        }

        location /product_catalog {
            set $upstream upstream_app_b;
            proxy_pass https://$upstream;
            proxy_ssl_name app_b.herokuapp.com;
            proxy_set_header x-forwarded-host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host app_b.herokuapp.com;
        }
    }

Please make sure you set correct value for header

proxy_set_header Host app_a.herokuapp.com

We managed to solve this issue by referring to article

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!