serve static files from Django Docker to nginx - django

I'm dockerizing Django application but static files are not being served.
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(os.path.dirname(BASE_DIR), 'static_my_project')
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_cdn', 'static_root')
docker-compose.yml
services:
nginx:
image: nginx:alpine
container_name: "originor-nginx"
ports:
- "10080:80"
- "10443:43"
volumes:
- .:/app
- ./config/nginx:/etc/nginx/conf.d
- originor_static_volume:/app/static_cdn/static_root
- originor_media_volume:/app/static_cdn/media_root
depends_on:
- web
web:
build: .
container_name: "originor-web"
command: ["./wait-for-it.sh", "db:5432", "--", "./start.sh"]
volumes:
- .:/app
- originor_static_volume:/app/static_cdn/static_root
- originor_media_volume:/app/static_cdn/media_root
ports:
- "9010:9010"
depends_on:
- db
db:
image: postgres:11
container_name: "originor-postgres-schema"
volumes:
- originor_database:/var/lib/postgresql/data
ports:
- "5432:5432"
pgadmin:
image: dpage/pgadmin4
container_name: "originor_pgadmin"
volumes:
- originor_pgadmin:/var/lib/pgadmin
volumes:
originor_database:
originor_static_volume:
originor_media_volume:
originor_pgadmin:
and nginx.conf
error_log /var/log/nginx/error.log;
include /etc/nginx/conf.d/proxy.conf;
proxy_headers_hash_bucket_size 128;
upstream dweb {
ip_hash;
server web:9010 fail_timeout=0;
}
server {
listen 10080;
server_name localhost;
access_log /var/log/nginx/localhost.access.log combined;
location /static/ {
autoindex on;
alias /app/static_cdn/static_root/;
}
location /media/ {
alias /app/static_cdn/media_root/;
}
location / {
proxy_pass http://dweb/;
}
}
But on access /admin/ in browser, it consoles
f032d416bce1_originor-web | Not Found: /static/admin/css/login.css
f032d416bce1_originor-web | Not Found: /static/admin/css/responsive.css
f032d416bce1_originor-web | Not Found: /static/admin/css/base.css
f032d416bce1_originor-web | Not Found: /static/admin/css/base.css
I can verify the files there in /app/static_cdn/static_root directory by executing
docker exec -it <container_id> ls -la /app/static_cdn/static_root
Edit 2: docker logs <container>
wait-for-it.sh: waiting 15 seconds for db:5432
wait-for-it.sh: db:5432 is available after 0 seconds
--: Starting application build
--: Creating migration
No changes detected
------: makemigrations complete
--: Running migration
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
------: migrate complete
--: load initial user data
--: load initial oauth app data
--: Running collectstatic
0 static files copied to '/app/static_cdn/static_root', 119 unmodified.
------: collectstatic complete
--: Starting Gunicorn.
[2019-01-11 13:26:47 +0000] [21] [INFO] Starting gunicorn 19.9.0
[2019-01-11 13:26:47 +0000] [21] [INFO] Listening at: http://0.0.0.0:9010 (21)
[2019-01-11 13:26:47 +0000] [21] [INFO] Using worker: sync
[2019-01-11 13:26:47 +0000] [23] [INFO] Booting worker with pid: 23
[2019-01-11 13:26:47 +0000] [24] [INFO] Booting worker with pid: 24
[2019-01-11 13:26:47 +0000] [25] [INFO] Booting worker with pid: 25
Not Found: /static/admin/css/fonts.css
Edit 3: nginx log
While running docker-compose up it gives the following log
But running docker logs originor-nginx it gives nothing

Somewhere in your 'web' initialization you must call manage.py collectstatic to put static files of application in your volume. More info https://docs.djangoproject.com/en/2.1/howto/static-files/
UPD:
nginx conf for uwsgi proxy:
location / {
uwsgi_pass uwsgi://web:9010;
include uwsgi_params;
}

Related

502 Bad Gateway for NGINX USWGI and Django app

I am having issues running this locally. I have two containers in my app. The Django app and the nginx server. Below are the config files and dockerfiles. I am getting a 502 on the localhost:8000 and the error message is
2021/11/16 01:18:29 [error] 23#23: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.30.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://127.0.0.1:8888", host: "localhost:8000", referrer: "http://localhost:8000/"
docker-compose.yml
version: "3.9"
services:
web:
build: .
container_name: test_deploy_web
hostname: blindspot
command: uwsgi --ini uwsgi.ini
volumes:
- .:/app/
- staticfiles:/app/static/
nginx:
build: ./nginx
container_name: test_deploy_nginx
volumes:
- staticfiles:/app/static/
ports:
- 8000:80
depends_on:
- web
volumes:
staticfiles:
app dockerfile
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN mkdir /app
WORKDIR /app
RUN pip install --upgrade pip
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY . /app
RUN python manage.py collectstatic --noinput
nginx dockerfile
FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
COPY my_nginx.conf /etc/nginx/sites-available/
RUN mkdir -p /etc/nginx/sites-enabled/\
&& ln -s /etc/nginx/sites-available/my_nginx.conf /etc/nginx/sites-enabled/\
&& rm /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
my_nginx.conf
# the upstream component nginx needs to connect to
upstream blindspot {
server 127.0.0.1:8888;
#server unix:/app/app.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name localhost;
# Django media
# location /media {
# alias /usr/src/app/static/media; # your Django project's media files - amend as required
# }
location /static {
alias /app/static/;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass blindspot;
include uwsgi_params; # the uwsgi_params file you installed
}
}
uwsgi.ini
[uwsgi]
wsgi-file = /app/blindspot/wsgi.py
socket = 127.0.0.1:8888
master=true# maximum number of worker processes
processes = 4
threads = 2# Django's wsgi file
module = blindspot.wsgi:application
vacuum=true

nginx: [emerg] host not found in upstream when dockerizing a django/react project

I'm trying to dockerize a django/react project but i'm running into this error when running docker-compose up.
i don't understand where the error come from.
i'm new to docker.
my goal is to deploy the frontend and the backend separately in one server.
nginx: [emerg] host not found in upstream
[emerg] 1#1: host not found in upstream "backend:8000" in /etc/nginx/conf.d/default.conf:2
nginx_1 | nginx: [emerg] host not found in upstream "backend:8000" in /etc/nginx/conf.d/default.conf:2
here is my code
django's Dockerfile
ENV DJANGO_SECRET_KEY $DJANGO_SECRET_KEY
ENV DJANGO_CORS_ORIGIN_WHITELIST $DJANGO_CORS_ORIGIN_WHITELIST
RUN mkdir /backend
WORKDIR /backend
COPY requirements.txt /backend/
EXPOSE 8000
RUN pip install -r requirements.txt
COPY . /backend/
RUN python manage.py makemigrations
RUN python manage.py migrate
react's Dockerfile
FROM node
USER root
WORKDIR /frontend
COPY . /frontend
ARG API_URL
ENV REACT_APP_HOST_IP_ADDRESS $API_URL
RUN yarn
RUN yarn config set ignore-engines true
RUN yarn build
server's config
upstream api {
server backend:8000;
}
server {
listen 8080;
location /api/ {
proxy_pass http://api$request_uri;
}
# ignore cache frontend
location ~* (service-worker\.js)$ {
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
expires off;
proxy_no_cache 1;
}
location / {
root /var/www/frontend;
try_files $uri $uri/ /index.html;
}
}
docker-copose.yml
version: '3'
services:
backend:
build:
context: ./ruelle_backend
args:
DJANGO_ALLOWED_HOSTS: http://ruelle-online.fr
DJANGO_SECRET_KEY: anis1807
DJANGO_CORS_ORIGIN_WHITELIST: http://ruelle-online.fr
command: gunicorn ivan_backend.wsgi --bind 0.0.0.0:8000
ports:
- "8000:8000"
frontend:
build:
context: ./ruelle_frontend
args:
API_URL: http://ruelle-online.fr
volumes:
- build_folder:/frontend/build
nginx:
image: nginx:latest
ports:
- 80:8080
volumes:
- ./webserver/nginx-proxy.conf:/etc/nginx/conf.d/default.conf:ro
- build_folder:/var/www/frontend
depends_on:
- backend
- frontend
volumes:
build_folder:

Docker-compose with Django, Redis, Gunicorn, Uvicorn, Nginx: Is my Nginx working?

I am trying to use docker-compose to setup the following:
Container 1: gunicorn to serve django WSGI + uvicorn to serve django ASGI (for websockets)
Container 2: redis server for websockets
Container 3: nginx server to handle HTTP/websocket requests and direct them to WSGI/ASGI respectively
However, after docker-compose up, my nginx server doesn't seem to be working.
I can run the app stack with no issues in communications between redis/django but I don't see my ngnix working anywhere.
My questions are:
1) How do I know that my nginx server is working? (i.e requests are not sent directly to gunicorn/uvicorn but via nginx)
2) Is this the correct setup?
Heres my docker-compose.yml:
version: '3.1'
services:
web_app_server:
restart: always
build: .
container_name: web_app_server
ports:
- "8007:8765"
- "8000:8000"
redis_server:
restart: always
image: redis
ports:
- "6379:6379"
nginx:
image: nginx:1.13
ports:
- 1337:80
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
depends_on: # <-- wait for djangoapp to be "ready" before starting this service
- web_app_server
At the end of the Dockerfile for building the web_app_server in docker-compose, I have
CMD ./dockerfile_start.sh
where dockerfile_start.sh contains:
killall gunicorn
killall uvicorn
./gunicorn_wsgi.sh &
P1=$!
./uvicorn_asgi.sh &
P2=$!
wait $P1 $P2
with gunicorn_wsgi.sh:
gunicorn locallibrary.wsgi:application --bind 0.0.0.0:8765
and uvicorn_asgi.sh
uvicorn locallibrary.asgi:application --reload --host 0.0.0.0 --port 8000
My nginx conf file ./config/nginx/conf.d:/etc/nginx/conf.d:
upstream django_app {
server web_app_server:8765;
}
upstream socker_server {
server web_app_server:8000;
}
server {
listen 80;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/nlp_app/NLP_Toolkit_App/src/Django/locallibrary;
}
location / {
include proxy_params;
proxy_pass http://django_app;
}
location /2/ {
proxy_pass http://socker_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
}
}
This is the printout after docker-compose up:
Creating nlp_toolkit_app_redis_server_1_c545837e3c21 ... done
Creating web_app_server ... done
Creating nlp_toolkit_app_nginx_1_c5c6fdde67ba ... done
Attaching to web_app_server, nlp_toolkit_app_nginx_1_46069f8268c6, nlp_toolkit_app_redis_server_1_58ff0cf70dd9
web_app_server | ./dockerfile_start.sh: 1: ./dockerfile_start.sh: killall: not found
web_app_server | ./dockerfile_start.sh: 2: ./dockerfile_start.sh: killall: not found
web_app_server | INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
web_app_server | INFO: Started reloader process [10] using statreload
web_app_server | [2020-05-11 11:36:02 +0000] [9] [INFO] Starting gunicorn 20.0.4
redis_server_1_58ff0cf70dd9 | 1:C 11 May 2020 11:36:02.774 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_server_1_58ff0cf70dd9 | 1:C 11 May 2020 11:36:02.774 # Redis version=6.0.1, bits=64, commit=00000000, modified=0, pid=1, just started
redis_server_1_58ff0cf70dd9 | 1:C 11 May 2020 11:36:02.774 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
web_app_server | [2020-05-11 11:36:02 +0000] [9] [INFO] Listening at: http://0.0.0.0:8765 (9)
web_app_server | [2020-05-11 11:36:02 +0000] [9] [INFO] Using worker: sync
redis_server_1_58ff0cf70dd9 | 1:M 11 May 2020 11:36:02.775 * Running mode=standalone, port=6379.
redis_server_1_58ff0cf70dd9 | 1:M 11 May 2020 11:36:02.775 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_server_1_58ff0cf70dd9 | 1:M 11 May 2020 11:36:02.775 # Server initialized
redis_server_1_58ff0cf70dd9 | 1:M 11 May 2020 11:36:02.775 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_server_1_58ff0cf70dd9 | 1:M 11 May 2020 11:36:02.775 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_server_1_58ff0cf70dd9 | 1:M 11 May 2020 11:36:02.776 * Ready to accept connections
web_app_server | [2020-05-11 11:36:02 +0000] [15] [INFO] Booting worker with pid: 15
web_app_server | /usr/local/lib/python3.6/dist-packages/librosa/util/decorators.py:9: NumbaDeprecationWarning: An import was requested from a module that has moved location.
web_app_server | Import of 'jit' requested from: 'numba.decorators', please update to use 'numba.core.decorators' or pin to Numba version 0.48.0. This alias will not be present in Numba version 0.50.0.
web_app_server | from numba.decorators import jit as optional_jit
web_app_server | INFO: generated new fontManager
web_app_server | INFO: Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex .
web_app_server | INFO: PyTorch version 1.4.0 available.
web_app_server | INFO: PyTorch version 1.4.0 available.
web_app_server | INFO: Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex .
web_app_server | INFO: PyTorch version 1.4.0 available.
web_app_server | INFO: Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex .
web_app_server | INFO: Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex .
web_app_server | INFO: Started server process [12]
web_app_server | INFO: Waiting for application startup.
web_app_server | INFO: ASGI 'lifespan' protocol appears unsupported.
web_app_server | INFO: Application startup complete.
Thanks for your help in advance.

Nginx working outside Docker but not inside

I'm making a personal website using Django, Gunicorn, Nginx and Docker. When I execute:
gunicorn --chdir personal-website --bind :8000 personal_website.wsgi:application
The output is:
[arturocuya#localhost personalwebsite]$ gunicorn --chdir personal-website --bind :8000 personal_website.wsgi:application
[2018-09-09 11:49:02 -0500] [5161] [INFO] Starting gunicorn 19.6.0
[2018-09-09 11:49:02 -0500] [5161] [INFO] Listening at: http://0.0.0.0:8000 (5161)
[2018-09-09 11:49:02 -0500] [5161] [INFO] Using worker: sync
[2018-09-09 11:49:02 -0500] [5165] [INFO] Booting worker with pid: 5165
And it works (kinda, configuration for static files is yet to be done)
The problem is that when I run the Docker container with sudo docker-compose up, I get 502 Bad Gateway
I'm suspecting that the problem is how I use the ports but I don't really understand how it should be done.
This is my folder structure
.
├── config
│   └── nginx
│   └── conf.d
│   └── local.conf
├── docker-compose.yml
├── Dockerfile
└── personal-website
└── manage.py
Dockerfile
# Start from an official image
FROM python:3.6
# The following is an arbitrary location choice
RUN mkdir -p /opt/services/personalwebsite/src
WORKDIR /opt/services/personalwebsite/src
# Copy the project code
COPY . /opt/services/personalwebsite/src
# Install dependencies
RUN pip install django gunicorn Pillow
# Expose Port 8000
EXPOSE 8000
# Define the default command to run when starting the container
CMD ["gunicorn", "--chdir", "personal-website", "--bind", ":8000", "personal_website.wsgi:application"]
docker-compose.yml
version: '3'
services:
personalwebsite:
build: .
volumes:
- .:/opt/services/personalwebsite/src
networks:
- nginx_network
nginx:
image: nginx:1.13
ports:
- 8000:80
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
depends_on:
- personalwebsite
networks:
- nginx_network
networks:
nginx_network:
driver: bridge
config / nginx / conf.d / local.conf
# first we declare our upstream server, which is our Gunicorn application
upstream personalwebsite_server {
# docker will automatically resolve this to the correct address
# because we use the same name as the service: "personalwebsite"
server personalwebsite:8000;
}
# now we declare our main server
server {
listen 80;
server_name localhost;
location / {
# everything is passed to Gunicorn
proxy_pass http://personalwebsite;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
I also made sure to modify ALLOWED_HOSTS inside the Django project's settings.py
ALLOWED_HOSTS = ['127.0.0.1', '149.248.5.164', '0.0.0.0']
Edit 1:
As someone suggested in the comments, I accessed the Nginx container with sudo docker-compose exec nginx bash and then did curl personalwebsite:8000. I got a DISALLOWED HOST error so I added personalwebsite to the allowed hosts in settings.py then I tried to curl again and the output was the HTML of my page, which is fine.
That seemed to do the trick inside the container because the output was the HTML of my page. But then I did sudo docker-compose up and i got 502 Bad Gateway again. The exact output was:
[arturocuya#localhost personalwebsite]$ sudo docker-compose up
[sudo] password for arturocuya:
Starting personalwebsite_personalwebsite_1 ... done
Starting personalwebsite_nginx_1 ... done
Attaching to personalwebsite_personalwebsite_1, personalwebsite_nginx_1
personalwebsite_1 | [2018-09-10 02:07:12 +0000] [1] [INFO] Starting gunicorn 19.9.0
personalwebsite_1 | [2018-09-10 02:07:12 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
personalwebsite_1 | [2018-09-10 02:07:12 +0000] [1] [INFO] Using worker: sync
personalwebsite_1 | [2018-09-10 02:07:12 +0000] [10] [INFO] Booting worker with pid: 10
nginx_1 | 172.26.0.1 - - [10/Sep/2018:02:07:17 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36" "-"
nginx_1 | 2018/09/10 02:07:17 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.26.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://172.26.0.2:80/", host: "0.0.0.0:8000"
nginx_1 | 2018/09/10 02:07:18 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.26.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.26.0.2:80/favicon.ico", host: "0.0.0.0:8000", referrer: "http://0.0.0.0:8000/"
nginx_1 | 172.26.0.1 - - [10/Sep/2018:02:07:18 +0000] "GET /favicon.ico HTTP/1.1" 502 576 "http://0.0.0.0:8000/" "Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36" "-"
Your Nginx configuration should be
upstream personalwebsite {
server personalwebsite:8000;
}
# now we declare our main server
server {
listen 80;
server_name localhost;
location / {
# everything is passed to Gunicorn
proxy_pass http://personalwebsite;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
Is your Nginx service is running inside the container?
Please hit the below command inside the Nginx container and let me know the output
curl -I localhost:80
It's very easy to understand, your proxy_pass URL and upstream keyword should be the same
For deep diving into Nginx upstream configuration go through the Link

NGINGX gives 502 Bad Gateway when trying to use NGINX + Gunicorn on Docker

I'm developing a Django app with a PostgreSQL database and I'm using NGINX + Gunicorn with Docker.
PostgreSQL, NGINX and Gunicorn are on different containers communicating with networks. I can build my app with docker-compose build but when I execute it with docker-compose up and view my app in the browser all I get is a 502 Bad Gateway error and in the terminal all I see is this:
nginx_1 | 127.0.0.1 - - [20/May/2018:01:53:01 +0000] "GET /home HTTP/1.0" 502 174 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "172.23.0.1"
nginx_1 | 172.23.0.1 - - [20/May/2018:01:53:01 +0000] "GET /home HTTP/1.1" 502 174 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-"
My docker-compose looks like this:
version: '3'
services:
# Database container
db:
image: postgres:10
volumes:
- db_volume:/var/lib/postgresql/data
env_file:
- ./.env
networks:
- db_network
# Web app container with gunicorn
webapp:
build: .
env_file: ./.env
volumes:
- .:/opt/services/webapp/src
- static:/opt/services/webapp/static
- media:/opt/services/webapp/media
networks:
- db_network
- nginx_network
depends_on:
- db
# NGINX (Reverse proxy) container
nginx:
image: nginx:1.13
ports:
- 8000:80
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static:/opt/services/webapp/static
- media:/opt/services/webapp/media
networks:
- nginx_network
depends_on:
- webapp
networks:
db_network:
driver: bridge
nginx_network:
driver: bridge
volumes:
db_volume:
static:
media:
And this is my Dockerfile:
# Start with an official Python image
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /opt/services/webapp/src
WORKDIR /opt/services/webapp/src
# Install dependencies
ADD requirements.txt /opt/services/webapp/src
RUN pip install -r requirements.txt
COPY . /opt/services/webapp/src
# Expose port 8000
EXPOSE 8000
# Default command to run when starting the container
CMD ["gunicorn", "-c", "config/gunicorn/conf.py", "--bind", ":8000", "--chdir", "myapp", "myapp.wsgi:application"]
This is my requirements.txt:
bcrypt==3.1.4
cffi==1.11.5
Django==2.0.4
Pillow==5.1.0
psycopg2==2.7.4
psycopg2-binary==2.7.4
pycparser==2.18
pytz==2018.4
six==1.11.0
django-phonenumber-field==2.0.0
gunicorn==19.8.1
gevent==1.3.1
And my NGINX configuration:
# Upstream server
upstream myapp_server {
server webapp:8000;
}
# Main server
server {
listen 80;
server_name localhost;
location /static/ {
alias /opt/services/webapp/static/;
}
location /media/ {
alias /opt/services/webapp/media/;
}
location / {
proxy_pass http://myapp_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1;
break;
}
}
}
I'm not sure about what could be causing this problem but it looks like gunicorn is not properly detecting my app, NGINX is working and PostgreSQL seems to be working too!
You need use proxy_pass to your upstream.
if (!-f $request_filename) {
proxy_pass http://myapp_server;
break;
}