testdrivenio/django-on-docker

nginx does not start...

apocalypse2012 opened this issue · 8 comments

Hello, this is the second time I have tried this tutorial. Each time I get right to the end of the NGINX section and am stopped by the fact that NGINX will not launch. That container will build, but not run...

Successfully built c11338b4c378
Successfully tagged django-on-docker_web:latest
Building nginx
Step 1/3 : FROM nginx:1.21-alpine
 ---> b46db85084b8
Step 2/3 : RUN rm /etc/nginx/conf.d/default.conf
 ---> Using cache
 ---> 210df3735621
Step 3/3 : COPY nginx.conf /etc/nginx/conf.d
 ---> Using cache
 ---> fbc4340866f8

Successfully built fbc4340866f8
Successfully tagged django-on-docker_nginx:latest
Creating django-on-docker_db_1 ... done
Creating django-on-docker_web_1 ... done
Creating django-on-docker_nginx_1 ... done

When I check the processes...

❯ docker-compose ps
         Name                       Command               State    Ports
--------------------------------------------------------------------------
django-on-docker_db_1    docker-entrypoint.sh postgres    Up      5432/tcp
django-on-docker_web_1   /home/app/web/entrypoint.p ...   Up      8000/tcp

When I go to the url (http://localhost:1337), the page is not found. This appears to be the most popular tutorial on the subject. I have already abandoned it once before when I was block on this and had to move on to other work. What is the missing magic that gets nginx to work. Last time I did the deep dive on this it seemed like their convoluted configuration system was somehow irredeemable broken. How are you getting it to work as specified in this tutorial?

Often, when you get a page not found like that, the underlying issue is with the application that you're trying to serve up not Nginx. I would focus time on figuring out if there is something wrong with the Django application, in other words. Have you looked at the Docker logs? If you expose the Django application itself via ports--

ports:
   - 8000:8000

--can you view the app from port 8000?

I'm not sure. I just tested it out and it works on my machine. (I'm on a mac).

test.mp4

Test it out in the same way. If it works, then you may have missed something in the tutorial. If it doesn't, then it may be an environment specific issue. What kind of machine are you on? I've updated this tutorial 3 or 4 times in the past few years, so it's been tested a number of times.

Yes

OK, trying this out again. The issue is not exactly as I reported before. Nginx does appear to be running. Its just giving me 404s. For some reason its not getting through to the app. Likewise, I cannot bring up the app by accessing port 8000. Not sure if this is for the same reason or if because port 8000 on the web app is not built with the expose flag instead of the ports flag and now is only supposed to be visible from other Dockers. Either way, the Nginx instance does not appear to be routing to it.
My only apparent variance from the source code in this project is that I have not yet added static files. It is otherwise the same as best as I can tell. Don't know why Nginx does not want to route to the app.

I'm sorry. For some reason, my iPad was not showing me your test.mp4 video, so I did not see the instructions you left. I reproduced your test case from git download and it works fine. I don't know what I missed or skipped in the following the tutorial. Doing a file by file diff to try to track it down.
Will follow up...

Found it! In the Nginx section of your tutorial: https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/#nginx
...there is a test link near the end of the section. This test link is to prove app operation through the nginx routing. At the point at which this link is presented, /admin is still the only valid url.
Here is the link as presented in the tutorial section...
http://localhost:1337/
If I were more experienced I would have likely caught it without even thinking about it. More over, I might have just not clicked the link, finished the tutorial without checking, and by the time I got to it, the link would have been good. As it is, it was just enough to send me flailing.