Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy_pass to another heroku app #59

Open
i8ramin opened this issue Sep 14, 2015 · 2 comments
Open

proxy_pass to another heroku app #59

i8ramin opened this issue Sep 14, 2015 · 2 comments

Comments

@i8ramin
Copy link

i8ramin commented Sep 14, 2015

Hi, wondering if its possible to use this setup to proxy certain paths to another heroku app. For example, the following nginx.conf works locally, but fails when deployed to Heroku.

daemon off;
# Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;

events {
  use epoll;
  accept_mutex on;
  worker_connections 1024;
}

http {
  gzip on;
  gzip_comp_level 3;
  gzip_min_length 150;
  gzip_proxied any;
  gzip_types text/plain text/css text/json text/javascript
    application/javascript application/x-javascript application/json
    application/rss+xml application/vnd.ms-fontobject application/x-font-ttf
    application/xml font/opentype image/svg+xml text/xml;

  server_tokens off;

  log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
  access_log logs/nginx/access.log l2met;
  error_log logs/nginx/error.log;

  include mime.types;
  default_type application/octet-stream;
  sendfile on;

  # Must read the body in 5 seconds.
  client_body_timeout 5;

  upstream app_server {
    server unix:/tmp/nginx.socket fail_timeout=0;
  }

  server {
    listen <%= ENV["PORT"] %>;
    server_name _;
    keepalive_timeout 5;

    root /app/public; # path to your app

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app_server;
    }

    location /static/ {
      rewrite ^/static/?(.*)$ /$1 break;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://my-other-app.herokuapp.com;
    }
  }
}
@arielperez82
Copy link

I was having the same issue. The problem is that nginx is automatically resolving http://my-other-app.herokuapp.com, so when you use $http_host, it's setting the entire list of IPs that this resolves to. I was able to solve this by explicitly setting the Host header to http://my-other-app.herokuapp.com. Hope that helps!

@stephengardner
Copy link

stephengardner commented Apr 6, 2018

The above solution is not correct. It is very close.

You have to set the Host header to my-other-app.herokuapp.com
Without the http://.
Phew, that took me a while.

Use this:
proxy_set_header Host my-other-app.herokuapp.com

AVDiv pushed a commit to AVDiv/nginx-buildpack that referenced this issue Dec 23, 2022
* start building archives

* use mime.types from stack archive

* build new archives and cleanup old binaries

* update bin/compile

* update bin/compile

* update changelog

* Update changelog

* update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants