Search code examples
dockernginxsslipport

How can I forward ports 80 and 443 from an external request through Nginx to ports 81 and 444, respectively?


I have docker containers with my own site and I would like to create external ports 444 and 81 from docker and connect it to a user request from my domain from external nginx on my linux machine. How do I organize the nginx.example1.conf file, I created the containers, I just have to connect the ports, how can this be done in the nginx.example1.conf file and am I doing the right thing?

In short, how do I write the nginx.example1.conf file correctly?

enter image description here


Solution

  • Same as any other reverse proxy configuration for nginX, the only difference will be that the endpoints are on localhost

    This is trivial example:

    server {
        listen 80;
        server_name foobar.net www.foobar.net test.io www.test.io;
    
        location / {
            proxy_pass http://localhost:81;
            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;
        }
    }