skip to Main Content

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:

enter image description here

But still the https calls are not forwarded to the container:

This works:

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


  1. The port mapping is incorrect to achieve your target.

    How to resolve:

      ports:
        - 1080:80
        - 10443:443
    

    should be changed into

      ports:
        - 80:1080
        - 443:10443
    

    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.

    Login or Signup to reply.
  2. 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:

    ports:
        - 10443:443
    

    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:

    1. Open Plesk panel
    2. Websites & Domains
    3. Click the needed domain, say "optimistic-spence.45-142-176-118.plesk.page"
    4. Hosting & DNS
    5. Apache & nginx
    6. nginx settings
    7. Disable "Proxy mode"
    8. "OK" to save changes and wait for redirect
    9. Apache & nginx (again)
    10. "Additional nginx directives" at the bottom of page

    Paste the following config:

    location / {
        proxy_pass https://45.142.176.118:10443;
        proxy_hide_header upgrade;
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
        access_log off;
    }
    

    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

    1. Hosting Settings
    2. Security
    3. "Permanent SEO-safe 301 redirect from HTTP to HTTPS" checkbox
    4. OK

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search