Django uwsgi Nginx not serving media files

三世轮回 提交于 2019-12-25 03:44:51

问题


Edit: I've made some progress trouble shooting this issue. For an update on the situation, read the comments and view this post on ServerFault: https://serverfault.com/questions/690836/django-uwsgi-nginx-not-serving-media-files-django-returns-404-status-code?noredirect=1#comment851441_690836

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     /home/a/Documents/CMS/CMS/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".

来源:https://stackoverflow.com/questions/30135986/django-uwsgi-nginx-not-serving-media-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!