Reverse proxy from NGINX container to Url on host

Hello, I had the same problem that I solved with https://www.sep.com/sep-blog/2017/02/27/nginx-reverse-proxy-to-asp-net-core-separate-docker-containers/

in docker-compose.yml :

mysite:
    (...)
    ports:
      - "9090:9090"

in conf.d/default.conf or nginx.conf :

upstream website {
    server mysite:9090;
}

Warning: the mysite name in the upstream part corresponds to the container name in docker-compose!

in part server:

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

in location / :

rewrite ^/(.*) /$1 break;
proxy_pass http://website;
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_set_header   X-Forwarded-Host $server_name;
proxy_redirect     off;
1 Like