我有一个
Django
项目,可以使用设置 Django
网络服务器进行工作。我想使用 nginx
和 uWSGI
。我在根 Django
文件夹中创建了一个名为 nginx/nginx.conf
和 nginx/default.conf
的目录来设置 nginx
。 Ir 成功在 http://localhost:8080
工作并显示 nginx 起始页面(站点也以 uwsgi --http :8000 --module brand_site.wsgi
开头)。但是当我尝试 http://localhost:8080/blog/corgifume-posts/
时,它显示 404 Not Found
。有什么问题?为什么我的网站无法使用 nginx
?
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /opt/homebrew/etc/nginx/uwsgi_params; # where my uwsgi_param stores in local machine
server_tokens off;
include /opt/homebrew/etc/nginx/default.conf;
}
默认.conf
server {
listen 8080; # what port to listen
server_name localhost;
location / {
proxy_pass http://127.0.0.1:8000; # where to address requests
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
uwsgi.ini
[uwsgi]
wsgi-file = config/wsgi.py
strict = true
socket = :8000
protocol = http
master = true
no-orphans = true
die-on-term = true
lazy-apps = true
processes = 4
threads = 8
enable-threads = true
max-requests = 500
reload-on-rss = 1024
worker-reload-mercy = 60
harakiri = 60
harakiri-verbose = true
vacuum = true
post-buffering = 1048576
buffer-size = 65535
我的网站路径:
/Users/nnhufg/Desktop/CORGIFUME/brand_site
您的
nginx
配置似乎基本正确,但您可能需要检查一些事项:
/blog/corgifume-posts/
URL。ALLOWED_HOSTS
中的 settings.py
设置是否包含 localhost
。uWSGI
服务器正在运行并正确为 Django 应用程序提供服务。uWSGI
进程具有访问您的 Django 项目文件的正确权限。此外,您可能需要在
location
配置中为静态文件添加 nginx
块:
location /static/ {
alias /path/to/your/static/files;
}
将
/path/to/your/static/files
替换为静态文件的实际路径。