简体   繁体   中英

uwsgi on Docker and Nginx as reverse proxy

I have an amazon EC2 instance (with Amazon Linux) with Nginx installed. I setup a python Flask Application and put that on a Docker container. The Docker file is here:

FROM apierleoni/flask-uwsgi:latest
EXPOSE 3001
WORKDIR /usr/src/app
RUN pip install --upgrade pip
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 3001

CMD [ "uwsgi", "--socket", "0.0.0.0:3001", \
               "--protocol", "http", \
               "--wsgi", "wsgi:app" ]

docker-compose.yml looks like this:

version: '3'
services:
  integration-app:
    container_name: integration-app-api
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - '.:/usr/src/app'
    ports:
      - '3001:3001'

I can access the Flask application routes over HTTP on port 3001 after running docker-compose up command

The Nginx reverse proxying doesn't work. It yields a 502 error. The Nginx configuration looks like this

upstream api_server2 {
 server 127.0.0.1:3001;
}



server {
    ...

    location /crm-project-api {
      include uwsgi_params;
      uwsgi_pass api_server2;
    }

    ...
}
upstream api_server2 {
 server 127.0.0.1:3001;
}
instead of this add:-
upstream api_server2{
 server integration-app:3001;  // container name
}

CMD [ "uwsgi", "--socket", "0.0.0.0:3001", \
               "--protocol", "http", \
               "--wsgi", "wsgi:app" ]

instead of http protocol add uwsgi

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