0

I want to use nginx to mapping the port from outside my ec2 server to "website" service I defined in docker-compose.yml as

website:
    build: .
    command: >
      gunicorn -c "python:config.gunicorn" "project.app:create_app()"
    environment:
      PYTHONUNBUFFERED: 'true'
    volumes:
      - '.:/project'
    ports:
      - '5000:5000'
    expose:
      - "5000"
    restart: always

and nginx service build as

nginx:
    build:
      dockerfile: Dockerfile
      context: ./nginx
    ports:
      - '3000:80'
      - '443:443'

    command: nginx -t -c /etc/nginx/default.conf

Dockerfile

FROM nginx:1.17.1


COPY ./default.conf /etc/nginx/default.conf

CMD ["nginx", "-g", "daemon off;"]

the test command return as successfully , then failed unexpected. How can I solve this problem?

nginx_1    | nginx: the configuration file /etc/nginx/default.conf syntax is ok
nginx_1    | nginx: configuration file /etc/nginx/default.conf test is successful
redis_1    | 1:C 21 Jul 2019 13:59:37.511 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1    | 1:C 21 Jul 2019 13:59:37.512 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1    | 1:C 21 Jul 2019 13:59:37.512 # Configuration loaded
collection-pro_nginx_1 exited with code 0

I think the problem come from default.conf file

default.conf file is as below

events {
  worker_connections 2048;
  multi_accept on;
  use epoll;
}

http{

  upstream website {
    server website:5000;
  }
  server {
    listen 80;

    location / {
       proxy_pass http://website;
    }
 }

}

changed the service name nginx to nginx-container, now the error finally come, nginx: [emerg] host not found in upstream "website:5000" in /etc/nginx/default.conf:11 close to the victory

Jayden
  • 61
  • 2
  • 5
  • Possible duplicate of [How to run Nginx within a Docker container without halting?](https://stackoverflow.com/questions/18861300/how-to-run-nginx-within-a-docker-container-without-halting) – David Maze Jul 21 '19 at 14:33
  • @David I added `CMD ["nginx", "-g", "daemon off;"]` at the end of Dockerfile but not working, still the same. the building phase is successful and started then shut down due to unknow reason – Jayden Jul 21 '19 at 14:47
  • The `command:` in your `docker-compose.yml` file overrides that `CMD` line. You should remove that. – David Maze Jul 21 '19 at 19:57
  • @David thank you! I didn't think about that. when i run localhost:3000, nginx is doing its job now, but returns me a 404 page. I shoud open a new question,while the codes are all here, do you have any idea what could be wrong about the config – Jayden Jul 22 '19 at 06:36
  • all problems are solved :) – Jayden Jul 22 '19 at 08:34

0 Answers0