Hide port number in URL exposed by NGINX Docker container

Dominik Krulak

I run Docker NGINX container with exposed ports 8080 and 8443.

So I visit welcome NGINX page at: http://www.nginx.test:8080


I'm trying to figure out IF it's possible to hide/remove port in URL.

So I visit welcome NGINX page at: http://www.nginx.test


Since the NGINX is reverse proxy server it should work. Still new to NGINX and I had to Google some answers and basically they are applied in tries bellow.

First I tried (didn't work) NGINX's directive proxy_redirect at server level like this:

server {
    listen 8080;
    listen [::]:8080;
    server_name www.nginx.test;

    proxy_redirect $scheme://$server_name:8080 $scheme://$server_name;
}

Then I tried (didn't work) NGINX's directive proxy_pass at location level like this:

server {
    listen 8080;
    listen [::]:8080;
    server_name www.nginx.test;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass $scheme://$server_name;
    }
}

Probably there's more than that to make it work.

zigarn

http://www.nginx.test is interpreted as http://www.nginx.test:80 (and with SSL https://www.nginx.test==https://www.nginx.test:443).

So you have to listen on port 80 if you want to drop it from the URL.

With docker, you can map a port of the host to a different port in the container.
So without changing the content of your NGINX container, you can simply map port 80 of your docker server to port 8080 of your nginx container:

docker container run ... --publish 80:8080 your_image ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to access a port exposed from a docker container?

Cannot Access Docker Container's Exposed Port

Cannot connect to exposed port of container started with docker-compose on Windows

Can I stop a docker container by its exposed port?

Docker port not being exposed

Change port number of docker service exposed publicly in jelastic

connecting to exposed docker container

Docker container not exposed on network

Docker container localhost not exposed

How to access the application(exposed on port 7600) from docker container inside a container?

Docker - Why is this express.js container with an exposed/published port reject connections? (using boot2docker)

Docker container/image running but there is no port number

Docker port exposed to outside world

Nginx remove port number :8080 in the url

Can't access publicly exposed Docker container port from external machine, only from localhost?

Docker Desktop for Windows: cannot access service on exposed port in windows container mode

Can't connect to Node.js inspector on exposed Docker container port

Can't access container exposed port

Why a angular container needs a exposed port to connect?

testcontainers - cannot connect to exposed port of generic container

SSH to port exposed by container - permission denied

docker-machine, create and run a nginx container is not exposing port 80

Nginx Reverse proxy for a docker container running at port 80

nginx/apache redirection for output port on docker container on vps

how to config nginx docker container to recognize localhost application in different port?

Nginx redirect https->http(reverse proxy)->port(docker container)

ELB redirecting 443/80 to single port on nginx docker container

Is it possible to unexpose port by Docker Compose if it is exposed in Dockerfile?

Docker service is unable to load on exposed port