Set proxy for a docker service thru subdomain.
Subdomain: your.domain.com
Docker Port: 9999
Edit docker-compose for an app you would like to proxy to. Add 127.0.0.1:9999, mapping it to a port in docker (here it’s 3000)
|
1 2 |
ports: - "127.0.0.1:9999:3000" |
Restart
|
1 2 |
docker compose down docker compose up -d |
Create nginx config, replacing
and
to docker port and subdomain of your choice.
|
1 |
sudo vim /etc/nginx/sites-available/your.domain.com |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
server { server_name your.domain.com; location / { proxy_pass http://127.0.0.1:9999; proxy_http_version 1.1; 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; } } |
Enable the subdomain and create cerrtificate.
|
1 2 |
sudo ln -s /etc/nginx/sites-available/your.domain.net /etc/nginx/sites-enabled/ sudo certbot --nginx -d your.domain.com |
Test nginx
|
1 |
sudo nginx -t |
If it does not throw errors, restart it
|
1 |
sudo systemctl reload nginx |
Point to your.domain.net
