Flask, Gunicorn, NGINX, Docker : What is properly the way to config SERVER_NAME and proxy_pass?

I setup docker project using Flask, gunicorn, NGINX and Docker, which works fine if I didn't add SERVER_NAME in Flask's setting.py.

The current config is :

gunicorn

gunicorn -b 0.0.0.0:5000

docker-compose.yml

services:
  application:
    #restart: always
    build: .    
    expose:
     - "5000"
    ports:
     - "5000:5000"
    volumes:
     - .:/code
    links:
     - db
  nginx:
    restart: always
    build: ./nginx
    links:
      - application
    expose:
      - 8080
    ports:
      - "8880:8080"

NGINX .conf

server {

    listen 8080;
    server_name application;
    charset utf-8;

    location / {
        proxy_pass http://application: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;
    }
}

Then I set the SERVER_NAME in Flask's setting.py

SERVER_NAME = '0.0.0.0:5000'

When I enter url 0.0.0.0:8880 to my browser, I get response 404 from nginx. What should be properly SERVER_NAME in Flask's setting.py ?

Thanks in advance.

Upvotes: 2

Views: 1592

Answers (2)

bodangly
bodangly

Reputation: 2624

It doesn't make sense to set an IP for SERVER_NAME. SERVER_NAME will redirect the requests to that hostname, and is useful for setting subdomains and also supporting URL generation with an application context (for instance lets say you have a background thread which needs to generate URLs but has no request context).

SERVER_NAME should match your domain where the application is deployed.

Upvotes: 0

Finally find the solution, I have to specific port for proxy_set_header

proxy_set_header Host $host:5000;

Upvotes: 2

Related Questions