A
A
Andrey Mironov2018-06-01 15:25:58
Nginx
Andrey Mironov, 2018-06-01 15:25:58

How to host multiple sites on one IP address in Docker?

Guys, please help. How to correctly build a configuration in Docker to host multiple sites on the same IP? In addition to all sorts of other ports, of course, it is 80 and 443 that are of interest. I understand that an address and port can have only one listener, but still, is this really considered impossible?
I am using nginx. The closest thing I found on the topic is jwilder/nginx-proxy , I should be interested in this, or are there other options? It is not possible to deal with this package, perhaps there will be some working examples?
Thank you very much!))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2018-06-01
@Elliemae

Raise another nginx container as a single entry point listening to external ports 80 and 443.
Depending on the domain, proxy to one or another internal ip of the container site.

F
fdroid, 2018-06-01
@fdroid

You can run docker containers with sites on different ports. For example, allocate port 81 to the container something like this:
That is, the site will be locally accessible via serverip:81
And in nginx, proxy to the container:

server {
    listen 80;
    server_name testcont.site;
    access_log /var/log/nginx/testcont.site-access.log;
    error_log /var/log/nginx/testcont.site-error.log;

location / {
    proxy_pass http://127.0.0.1:81;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    }
}

Thus, when going to tescont.site, nginx redirects the request to the internal container 127.0.0.1:81.
Https is easiest to set up via Certbot , which itself will receive certificates and set up a redirect from http to https in the site configs.
Of course, ports 80 and 443 must be open on the server, this is enough.

I
intelligence, 2018-06-08
@intelligence

You can look towards https://traefik.io/ as an edge proxy for all projects. It will listen on port 80\443 and automatically detect new services if you add the appropriate labels when starting containers. There is also let's encrypt auto-receipt and a bunch of goodies.
But it should be borne in mind that this is a pure reverse proxy, it will not work very well to wind up features from nginx there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question