我最初在 SO 上发布了这个,但我认为它可能属于这里。
我正在关注这个教程: http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
一切都很顺利,直到我到达“基本 nginx 测试”部分。当我停止并启动 nginx,然后将“media.png”添加到我的媒体文件夹并转到
192.168.***.***:8000/media/media.png
它给了我一个 404 状态代码。请注意,此状态代码由 Django (DEBUG=True) 给出,因此它显示:
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:
这是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
}
}
知道为什么我在尝试查看媒体文件时出现 404 错误吗?
附加信息:当我去
http://192.168.***.***:8001/media/media.png
或者
127.0.0.1:8001
它显示“该网页不可用”。
请注意,我是服务器方面的新手,所以我基本上完全遵循教程中的内容,我没有做任何额外的“常识”事情,因为我才刚刚开始并正在学习它(例如,我没有在我的 settings.py 文件中定义 MEDIA_URL 或 MEDIA_ROOT,因为教程还没有指导我这样做)。