1

I originally posted this on SO but I think it might belong here instead.

I'm following this tutorial: http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Everything was going well until I reached the "Basic nginx test" section. When I stopped and started nginx and then added "media.png" to my media folder and went to

192.168.***.***:8000/media/media.png 

it gave me a 404 status code. Note that this status code was given by Django (DEBUG=True), so it says:

Page not found (404)
Request Method: GET
Request URL:    http://192.168.***.***:8000/media/media.png
Using the URLconf defined in CMS.urls, Django tried these URL patterns, in this order:

This is mysite_nginx.conf:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name 192.168.***.***; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /home/a/Documents/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/a/Documents/CMS/CMSApp/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}

Any idea why I'm getting a 404 error when trying to view the media file?

Additional information: When I go to

http://192.168.***.***:8001/media/media.png

or

127.0.0.1:8001

it says "This web page is not available".

Note that I am new to dealing with servers so I basically followed exactly what is in the tutorial, I didn't do any extra "common sense" things because I'm just getting started and learning it right now (for example, I didn't define MEDIA_URL or MEDIA_ROOT in my settings.py file because the tutorial didn't instruct me to yet).

user2719875
  • 129
  • 1
  • 7
  • What do you see in nginx' access and error logs? – Louis May 10 '15 at 17:40
  • @Louis I reran Django / uWSGI on 8001 and Nginx on 8000. Now when I go to 127.0.0.1:8000/media/media.png Nginx serves the file properly. When I go to 127.0.0.1:8000/CMS/users Django is supposed to search urls.py but instead, Nginx returns a 504 Gateway timeout status code. I checked the Nginx error log and it says "*6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 127.0.0.1, server: 192.168.174.131, request: "GET /CMS/users HTTP/1.1", upstream: "uwsgi://127.0.0.1:8001", host: "127.0.0.1:8000". I'm searching for the uWSGI error log right now. – user2719875 May 10 '15 at 17:46
  • @Louis any idea where the uWSGI error log file is? I can't seem to find it. – user2719875 May 10 '15 at 18:06
  • /var/log/uwsgi/ on a Debian system. – Louis May 10 '15 at 18:16
  • @Louis it's not there for me unfortunately, probably because I installed uwsgi using pip. I checked "myVirutalEnv/python3.4/site-packages/uWSGI-2.0.10-py3.4.egg-info" and there is no error log file. I made a SO post asking where the error log file is if I installed it using pip: http://stackoverflow.com/questions/30154661/where-is-the-uwsgi-error-log-file-when-installing-uwsgi-using-pip – user2719875 May 10 '15 at 18:27
  • Did you ever solve this? I'm running into the exact same problem right now and pulling my hair out. – zoltar Apr 14 '18 at 12:22

0 Answers0