Some Docker containers expose ports so that applications in containers
could be accessible via those ports.
When you use an application in Docker container on your website, you may
find it inconvenient to specify the non-standard port in its URL. To
avoid inconvenience, you can set up nginx to proxy requests from domains
to that port, so domains can use a standard port (such as 80) and there
is no need to explicitly specify the port in URL.
Requirements
- nginx must be running in Plesk.
- You must map the port inside a container to a port on the host system
(for example, 32768) manually (Docker > select a container >
Settings > clear the option Automatic port mapping).
After you have mapped the port inside a container manually to some port
on your system (for example, 32768), you can set up nginx to proxy
requests from domains to that port, so domains can use a standard port
on nginx (for example, 80). To make this possible, add a rule for nginx
in the domain settings in the following way:
Go to Websites & Domains > the domain > Proxy Rules > Add
Rule and specify the following:
-
URL. Specify the URL of the website that uses an application
running in a container. It can be either the main website or a part
of it. - Container. Select the application running as a Docker container.
-
Port. Select one of the mappings that was specified in the
container settings (a port inside a container mapped to a port on
your system). Nginx will proxy requests to the port on the system.
Proxy rules are implemented in the web server configuration, e.g., in
the website’s
file nginx.conf
(in /var/www/vhosts/system/$domain/conf/
):
#extension docker begin
location ~ ^/.* {
proxy_pass http://0.0.0.0:9080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#extension docker end
Proxy rules should work fine on servers behind NAT.
Note: Docker containers connected via Proxy Rules to a website are not
counted towards the subscription’s disk space usage. An exception to
this would be when a website directory is mounted to a Docker
container as a volume, as in this case all files located in the
container will be counted towards the disk space usage of the
website.