Skip to content

Instantly share code, notes, and snippets.

@nhthai2005
Last active April 18, 2022 08:00
Show Gist options
  • Save nhthai2005/8993478b4d898ddf499ed50411d75c44 to your computer and use it in GitHub Desktop.
Save nhthai2005/8993478b4d898ddf499ed50411d75c44 to your computer and use it in GitHub Desktop.
Howto Configure port-forward using nginx

Howto Configure port-forward using nginx

Create nginx-portforward directory

mkdir nginx-portforward && cd nginx-portforward

Download nginx-portforward.conf and nginx-portforward.yml

curl -LO https://gist.githubusercontent.com/nhthai2005/8993478b4d898ddf499ed50411d75c44/raw/18712ed7232a9b07c9bba1439474a1329d802fcd/nginx-portforward.conf
curl -LO https://gist.githubusercontent.com/nhthai2005/8993478b4d898ddf499ed50411d75c44/raw/18712ed7232a9b07c9bba1439474a1329d802fcd/nginx-portforward.yml

Run docker-compose

docker-compose -f nginx-portforward.yml up -d

server {
listen 8080; # forward from 192.168.56.4:8080 to 192.168.56.201:8080
client_max_body_size 64M;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://192.168.56.201:8080;
proxy_redirect off;
}
}
version: '3'
services:
nexus:
image: nginx:latest
container_name: nexus_portforward
restart: unless-stopped
volumes:
- ./nginx-portforward.conf:/etc/nginx/conf.d/nginx-portforward.conf:ro
ports:
- 192.168.56.4:8080:8080 # forward from 192.168.56.4:8080 to 192.168.56.201:8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment