Applicable to:
- Plesk for Linux
Question
Docker containers can expose ports so applications inside them could be accessible via those ports.
But it is inconvenient to use the non-standard port in the website's URL to access an application.
How to proxy requests from domains to a Docker container to access the application in the container without using the non-standard port?
Answer
Note: Ensure that Nginx is installed before applying any steps. To check it open Tools & Settings > Updates & Upgrades > Install components, fill in root password and press Next. On next screen ensure that nginx component is checked under Web hosting category and press Next to install it (if not installed).
- Log into Plesk.
- Go to Tools & Settings > Services management and ensure that nginx service is running. If nginx is not running, press Run (green button with "play" sign).
- Map the port inside a container to a port on the host system (for example, 32768) manually under Docker > select a container > Settings > clear the option "Automatic port mapping".
- Set up nginx to proxy requests from domains to that port, so domains can use a standard port on nginx (for example, 80).
Go to Domains > example.com> 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 were 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.
Additional information
Docker container does not start with error: No chain/target/match by that name
Not possible to add Docker Proxy rules, no container is displayed
Comments
14 comments
Im currently using the Litespeed Webserver addon which requires Nginx to be turned off to work. How can i run nginx only for docker proxy without interfering with my litespeed webserver? Or is this impossible?
Hi @Blake Moore.
Nginx can be enabled only server-wide, so in case of Litespeed it is hardly an option. In theory, it should be possible to configure some sort of proxy in Litespeed configuration files manually, however this scenario was not tested and it will be impossible to manage this via Plesk as described in the article.
Hi, is it possibe to add a rule that routes mydomain.com/ ports 80 & 443 to the same docker image ?
Hello Andy,
If I understood you correctly, you mean that your image also uses ports 80 and 443 inside.
This article describes your case.
Following the guide, you need to map image port with external, for example, 32768.
After that, the step 4 allows to redirect your domain via ports 80 and 443 to external image ports.
Hi Ivan no, my image uses different ports which are mapped to ports 80 & 443 as per the first image in the article. I have done this the problem is when setting up the proxy rule i can select to forward either port 80 or port 443 to my container not both.
Hello Andy,
Plesk interface allows mapping only one port to Docker container at a time. This is behavior by design.
Vote for this feature, and leave your feedback as a comment here (top voted ideas are likely to be implemented in next product releases):
https://plesk.uservoice.com/forums/184549-feature-suggestions/suggestions/36927160-plesk-ui-domain-domainname-docker-proxy-rul
I have an odoo instance running with docker and that instance is proxied to a domain that has SSL certificate installed.
If I visit https://oddosamplesite.com it will navigate under SSL but if I logout goes back to the non secure version.
How can I force the use of HTTPS on this instance?
Hello @Gonzalo Besoain
Please make sure that option "Permanent SEO-safe 301 redirect from HTTP to HTTPS" is enabled for the domain in Plesk > Domains > oddosamplesite.com > Hosting Settings.
If the issue still persist please submit a ticket to technical support under the link: https://support.plesk.com/hc/en-us/requests/new
I would like, if I have configured the port map in docker as 3330->3333, to be able to set a redirection in nginx as 6666->3330.
Is this possible? (https:6666 -> 3330 -> 3333)
Manually I can do it by modifying the nginx conf of the domain (listen x.x.x.x:443 ssl http2 ==> listen x.x.x.x:6666 ssl http2).
This way I can automatically assign the certificate of an SSL connection using 6666.
But of course, when the file is regenerated, the change is lost...
Hi Nerque, if you don't want to loose the changes when the file regenerated you can use configuration templates as described here https://support.plesk.com/hc/en-us/articles/115000276014-How-to-create-custom-Apache-and-nginx-configuration-files-for-all-domains.
In that way then the file regenerated you will not loose the changes.
Does it work for someone?, I am looking for help everywhere and there is silence, nobody knows anything?
https://talk.plesk.com/threads/docker-with-nginx-proxy-502-bad-gateway.355741/#post-874816
Hello Roman Bendik
As I can see, you've solved the issue on your side.
It would be great if you could share steps you've used to resolve the issue.
So for all the Litespeed users out there scratching their heads on how to achieve this, I've put together a very straight forward guide that uses the WebAdmin Console + Apache directives:
https://smallbyte.tech/2020/06/27/how-to-plesk-litespeed-docker-reverse-proxy/
It's much easier than you'd think, it's a shame that Plesk doesn't support this, it's 100% possible, it would simply need to detect if LSWS was being used and if so amend its process for making configuration changes to add extProcessor in the httpd_config.xml and add directives to Apache Vhost Config.
Hope this helps some of you.
The port forwarding as described above works fine, but I have the following problem while trying to integrate one of our Docker-Container in Plesk:
We are using a homebrew Docker Container which has to be run with a few additional parameters with the run-command in the console to work properly. (autorestart, custom entrypoint, etc.)
However: I'm pretty sure, when I try to forward the ports like mentioned above, Plesk scraps the old container and starts a new one based on the Image, overwriting the parameters I initialy gave in the console.
Is there a way to set up the port forwarding so I can use them in Domains > example.com> Proxy Rules > Add Rule , without me having to use the Docker Plugin Interface for the initial port forwarding?
Also our docker container has an extended time frame for stopping gracefully, before it gets killed by docker. This results in a Plesk timeout before the container is stopped. Is there a way to increase the timeout Plesk waits for a docker container to stop?
Please sign in to leave a comment.