0

I am running flask application with nginx and Gunicorn, I am getting below error:

[root@master nginx]# curl http://127.0.0.1
curl: (7) Failed connect to 127.0.0.1:80; Connection refused
[root@master nginx]# curl http://127.0.0.1:80
curl: (7) Failed connect to 127.0.0.1:80; Connection refused
[root@master nginx]# curl http://127.0.0.1:8080
curl: (56) Recv failure: Connection reset by peer

Note: For some reason I should not use docker compose. Everywhere examples with docker compose only, not sure multi container can be achieved without docker compose.

I can directly access Flask api endpoint

[root@master nginx]# curl http://127.0.0.1:5000
Hello, World![root@master nginx]#

I am running Flask api docker image like below:

docker run -d -p 8080:80 nginx-frontend

I am running nginx like below:

 docker run -d -p 8080:80 nginx-frontend

Both nginx and flask are running in same host and nginx.conf is below and i guess i am doing something wrong here

worker_processes  3;

events { }

http {

  keepalive_timeout  360s;

  server {

      listen 80;
      server_name 127.0.0.1;
      charset utf-8;

      location / {
          proxy_pass http://127.0.0.1:5000;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
}

Nginx docker file:

FROM nginx:1.15.2

RUN rm /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx

Python Flask Docker file:

FROM python:3.8-slim
RUN mkdir /app
WORKDIR /app
ADD requirements.txt /app
RUN pip3 install -r requirements.txt
ADD . /app
RUN chmod +x ./entrypoint.sh
EXPOSE 5000:5000
ENTRYPOINT ["sh", "entrypoint.sh"]

app.py

from flask import Flask
app = Flask(__name__)

app.config['DEBUG'] = True

@app.route("/")
def hello_world():
    return "Hello, World!"

if __name__ == "__main__":
    app.run(host='0.0.0.0')

Complete reference code:

Code Repo

Vidya
  • 547
  • 1
  • 10
  • 26

1 Answers1

0

Try this solution.

You will need to modify the ConfigMap.

See: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_client_abort

dikokob
  • 85
  • 3
  • 12