I have an nginx container running in the host of my Plesk with this docker compose configuration:
# docker-compose.yml
[...]
web:
build:
context: .
dockerfile: ./docker/web/DockerFile
depends_on:
- app
ports:
- 1080:80
- 10443:443
volumes:
- .:/var/www/app
restart: always
It was ok if I access to the host using the specific port:
But I don’t know how to make the proper port forwading:
- example.com:443 -> docker:10443
- example.com:80 -> docker:1080
I know the quick answer is using Proxy Rules but it just doesn’t work for me, I set this rule:
But still the https calls are not forwarded to the container:
- https://example.com (still opens the plesk default site)
This works:
- https://example.com:10443 (opens the nginx site)
The other problem I am heading is that Proxy Rules only allows me to set one rule per URL Route (even if the port is different) and I need to set up 2 rules for the same route:
- example.com:443 -> docker:10443
- example.com:80 -> docker:1080
TL;TR:
- How to forward all requests to example.com/* 443 and 80 ports to my docker container?
2
Answers
The port mapping is incorrect to achieve your target.
How to resolve:
should be changed into
Reason:
in port mapping, the one on the left of the colon is port in the host, while the one on the right of the colon is port in the container.
It seems that OP wanted achieving a different goal. I recently had same issue as described in the initial post and have resolved it. It works with Docker’s config:
Port 443
I did the following to overcome Plesk (Obsidian v. 18.0.53) default page config and forward users’ requests from a browser’s "regular" HTTPS 443 port to Docker’s 10443 port:
Paste the following config:
An FQDN "optimistic-spence.45-142-176-118.plesk.page" can be used instead of "45.142.176.118". However IP is expected to work faster because an FQDN should be first resolved to IP anyway to my understanding.
Port 80
I have redirect from HTTP to HTTPS in subdomain by Plesk. So I did not add extra config for port 80 because it was not needed in my case. I have in done it via
TL;DR
The port 443 is occupied by default nginx configuration and Plesk puts a stub HTML page there. Thus by default a Dockerised app can be reached via nGinx by a port other than 443 only as webserver can’t listen to HTTPS port because of Plesk.