简体   繁体   中英

simple nginx reverse proxy not working in docker compose

fhsmgr proxy works at / but not any other location with 404

fhsdir proxy gives 404 at /dir, though when i browse directly to it on localhost:5000 i get the expected output, so the host is up and running. also, nginx does not complain about invalid host and exit like i've seen it do before.

  • i have tried trailing '/' so '/dir/' to no avail.
  • i have tried putting fhsmgr at '/mgr' and i get the expected 404 at index '/' but then 404 again at '/mgr'.
  • i have tried without proxy_redirect off; as well.
  • i have removed the upstream statements and just directly put in container names

seemingly the only thing it'll let me proxy is at '/', though i know i've proxied to other servers at different location paths in setups like this before.

-- docker compose

version: "3.7"
services:
  
  fhsmgr:
    build: fhsmgr
    restart: always

  fhsdir:
    build: fhsdir
    restart: always
    ports:
      - 5000:5000

  nginx:
    build: nginx
    restart: always
    ports:
      - 80:80
    environment:
      - NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx
      - FHSMGR_HOST=fhsmgr
      - FHSMGR_PORT=5000     
      - FHSDIR_HOST=fhsdir
      - FHSDIR_PORT=5000   

-- nginx conf

events {}

http {

    # upstream fhsmgr {
    #     server ${FHSMGR_HOST}:${FHSMGR_PORT};
    # }

    # upstream fhsdir {
    #     server ${FHSDIR_HOST}:${FHSDIR_PORT};
    # }

    # a simple reverse-proxy
    server {

        listen 80 default_server;

        location / {
            proxy_pass http://fhsmgr:5000;
            proxy_redirect     off;
        }

        location /dir {
            proxy_pass http://fhsdir:5000;
            proxy_redirect     off;
        }
    }
}

i am modifying this project https://github.com/AwsGeek/lightsail-containers-nginx to get it to work for my use case. Haven't gotten to lightsail, just using docker compose locally

You miss the container_name in your docker-compose,try this

version: "3.7"
services:
  
  fhsmgr:
    build: fhsmgr
    restart: always
    container_name: fhsmgr # allow other containers to access by container_name
  
  fhsdir:
    build: fhsdir
    restart: always
    container_name: fhsdir 
    ports:
      - 5000:5000

  nginx:
    build: nginx
    restart: always
    ports:
      - 80:80
    environment:
      - NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx
      - FHSMGR_HOST=fhsmgr
      - FHSMGR_PORT=5000     
      - FHSDIR_HOST=fhsdir
      - FHSDIR_PORT=5000  

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