Milo Anderson
Milo Anderson

Reputation: 21

Nothing is written to Nginx access.log/error.log - how to troubleshoot?

I have a Django project deployed with Docker on DigitalOcean. I based it off this tutorial, but had to change some things to get it working. I'm getting a 500 error when I try SMTP email registration live (works fine locally), and the proximate issue is that I can't get any more information about this error because nothing is being written to the nginx access.log/error.log (files are always empty) and there's no output to any docker logs I can find.

I've been all over Stack Overflow and the Internet-at-large, but found no help. I've tried changing permissions/owner on the log files to match the Nginx worker, made no difference. I've tried re-specifying the default log files (/var/log/nginx/error.log) in Nginx configuration, even though it seems like I shouldn't have to, and that made no difference either.

Here's what I have in nginx/sites-enabled:

server {

    listen 80;
    server_name 134.209.172.141;
    charset utf-8;

    location /static {
        alias /www/static;
    }

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

}

...and the nginx Dockerfile:

FROM tutum/nginx

RUN rm /etc/nginx/sites-enabled/default

COPY sites-enabled/ /etc/nginx/sites-enabled

I don't specify an nginx.conf file, but I notice if I shell into the nginx container there is such a file at /etc/nginx/nginx.conf. Perhaps this comes by default with the Docker image?

Here is the docker-compose.yml I use for building:

version: '3'

services:
  web:
    restart: always
    build: ./web
    expose:
      - "8000"
    links:
      - postgres:postgres
      - redis:redis
    volumes:
      - web-django:/usr/src/app
      - web-static:/usr/src/app/static
    env_file: .env_prod
    command: /usr/local/bin/gunicorn cpm_project.wsgi:application -w 2 -b :8000

  nginx:
    restart: always
    build: ./nginx/
    ports:
      - "80:80"
    volumes:
      - web-static:/www/static
    links:
      - web:web

  postgres:
    restart: always
    image: postgres:latest
    volumes:
      - pgdata:/var/lib/postgresql/data/

  redis:
    restart: always
    image: redis:latest
    ports:
      - "6379:6379"
    volumes:
      - redisdata:/data

volumes:
  web-django:
  web-static:
  pgdata:
  redisdata:

After countless hours of tinkering I had something that works, in spite of large gaps in my understanding of docker/nginx. But when I added SMTP to Django settings.py and tried to test email registration live, I get the 500 error after clicking the "register" button; and then after hours and hours of researching & trying different things & tearing my hair out, I have no further information on this error and nothing that looks like even a glimmer of a clue to the actual problem, let alone a solution. It seems like getting the Nginx logs working is a good place to start, but I'd be grateful for any clarity at all.

Happy to post any other code that might be useful, didn't want to inundate you.

Upvotes: 1

Views: 3454

Answers (1)

Milo Anderson
Milo Anderson

Reputation: 21

Got it figured out. In case someone else is having similar issues, the workaround that finally got me somewhere was to define a new error log file in my sites-enabled, adding this line:

error_log /var/log/nginx/new_error.log debug;

At about the same time I realized I could just temporarily set DEBUG=True in Django settings & get detailed error messages right in the browser. This seems totally obvious in retrospect, but it didn't occur to me for some reason.

The ultimate issue with the 500 error turned out to be security settings on the smtp server, nothing to do with my code.

Upvotes: 1

Related Questions