编辑:我重新按照说明进行操作,现在这是我遇到的问题:Django Nginx not serving media files
我正在关注本教程: http ://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
一切都很顺利,直到我到达“基本 nginx 测试”部分。当我停止并启动 nginx,然后将“media.png”添加到我的媒体文件夹并转到 192.168.** *.** *:8000/media/media.png 它给了我一个 403 Forbidden 状态码。
当我访问 192.168.** *.** *:8000 时,它会给出 502 Bad Gateway 状态代码。
这是 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
}
}
知道为什么 nginx 会返回这些状态代码以及如何解决问题(如何让它向我显示“media.png”图像)?