Articles in this section

How to proxy web requests from domains to Docker containers via nginx in Plesk?

kb: how-to Plesk for Linux ext: docker

Applicable to:

  • Plesk for Linux

Question

Docker containers can expose internal Docker network ports to external virtual server ports, so applications inside them could become accessible via those ports, however it is inconvenient to use the non-standard port in the website's URL to access an application.

How to proxy web requests that are incoming towards the Plesk web server on ports 443 and 80 via domains to a Docker container, in order to access the application in the container without using the non-standard port?

Answer

Note: Make sure that Nginx is installed and enabled on your server by using the steps here. Also, make sure that the Docker extension is installed by using the steps here.

  1. Log into Plesk
  2. Go to Tools & Settings > Services management and ensure that nginx service is running. If nginx is not running, press Run (green button with the Play icon).
  3. Go to Docker > select a container > Settings icon (on the right) > Uncheck the Automatic port mapping box and map the port inside the Docker container to an external port on the virtual server host system (for example, 32222) manually:

    Note: In the example above, both ports 3000 and 32222 are managed by Docker, thus incoming requests received on port 32222 will be forwarded to port 3000 on your Docker container via the Docker proxy automatically.
  4. Go to Domains > example.com> Dashboard > Docker Proxy Rules > Add Rule and set up nginx to proxy requests that are incoming via domains on ports 443 and 80 to that external Docker port (32222 in the example above) by specifying the following:
    • URL - Specify the URL of the website that uses an application running in a Docker container. It can be either the main website or a part of it.
    • Container - Select the name of the Docker container that should be served via the domain
    • Port - Select the port mapping combination that you have specified in the Docker container settings. The nginx web server will proxy requests that are incoming on ports 80 and 443 towards the external Docker port (32222 in this example), which is automatically proxied to the internal Docker container port (3000 in this example)

Once all of this is done, you should be able to view the Docker container website content while visiting the domain.

Was this article helpful?

Comments

2 comments
Date Votes
  • info is outdated

    0
  • article is outdated, there is no option “Add proxy rules” or “Proxy rules” under domains
     

    0

Please sign in to leave a comment.