我有一个 django 应用程序,其中 hompage 路由正确,但是当我尝试单击任何链接时,我收到 404 错误。我查看了日志并看到:
*1 open() "/usr/share/nginx/html/pricing" failed (2: No such file or directory)
这告诉我 nginx 不是在查看我的项目文件夹,而是在查看默认设置。我使用的是 centos,所以我必须手动设置可用的站点和已启用的站点,这是我用来使主页正常工作的。因此,没有要禁用的默认配置。我不确定如何让 nginx 路由到我的路径而不是默认路径。我的 nginx.conf 文件如下所示:
user so_dev;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; #added by me
}
最佳答案
我遵循了一个糟糕的教程,其中有一个错字。如果您碰巧遵循相同的类型,则应在您的 nginx 站点可用文件中放置:
location /
并不是
location = /
https://www.shellvoide.com/hacks/installing-django-application-with-nginx-mysql-and-gunicorn-on-ubuntu-vps/
关于django - Nginx 路由 Django Web App 链接到错误的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60555195/