gilyes / docker-nginx-letsencrypt-sample

Dockerized Nginx + Let's Encrypt sample
https://gilyes.com/docker-nginx-letsencrypt
385 stars 185 forks source link

Reverse proxy for host service #4

Open SYip opened 7 years ago

SYip commented 7 years ago

Hello, I would like to ask how could I config it to reverse proxy to host service port 5000. I am not fimiliar with nginx config.

hartmark commented 2 years ago

I had same question myself and it was a bit tricky to get sorted.

You can use the sample web site and add a "qb.conf" under this folder: ./docker-nginx-letsencrypt-sample/volumes/nginx-sample-website/conf.d

With this content:

upstream qb_host {
  # specify extra-host in docker-compose.yml or specify IP here straight away
  server host.docker2.internal:8080;
}

server {
  location /qb {
    proxy_http_version  1.1;
    proxy_cache_bypass  $http_upgrade;

    proxy_set_header Upgrade           $http_upgrade;
    proxy_set_header Connection        "upgrade";
    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-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Port  $server_port;

    # add a trailing slash if just ending with /qb
    rewrite ^([^.]*qb[^/])$ $1/ permanent;

    # drop qb from url
    rewrite ^/qb/?(.*)$ /$1  break;
    proxy_pass https://qb_host;
  }
}

Then you need to add this to the end of the docker-compose.yml:

    extra_hosts:
      - host.docker2.internal:192.168.1.50