Answer the question
In order to leave comments, you need to log in
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
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.
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;
}
}
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 questionAsk a Question
731 491 924 answers to any question