简体   繁体   中英

Does accessing a remote server IP address via the browser default resolve to port 80?

I have a containerized app that uses nginx as a reverse proxy. If I map nginx ports as 1337:80 I am only able to reach my website at <MY_INSTANCE_IP>:1337 . If I instead map nginx ports as 80:80 I am able to reach my website at <MY_INSTANCE_IP> . Changing the ports in my docker-compose file worked but I'd like to know why.

My docker-compose config:

version: '3.7'

services:
  web:
    build:
      context: .
      dockerfile: ./compose/production/flask/Dockerfile
    image: flask_web
    command: /start
    volumes:
      - .:/app
    expose:
      - 5000
    env_file:
      - .env/.prod
    environment:
      - FLASK_APP=app

  nginx:
    build: ./compose/production/nginx
    ports:
      - 80:80
    depends_on:
      - web

My nginx config:

upstream flask-app {
    server web:5000;
}

server {
    listen 80;
    server_name <MY_INSTANCE_IP>;
    location / {
        proxy_pass http://flask-app;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        # client_max_body_size 20M;
    }
}

So, you have nginx set to listen on port 80 (default http). When you set the port for your nginx service in docker-compose the first number is the port that docker will "publish" the service on the host and the second number, after the colon (:), is the port the server is listening on "inside" the container. See: https://docs.docker.com/config/containers/container-networking/#published-ports for more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM