【问题标题】:Nginx routing Django Web App links to wrong pathNginx 路由 Django Web App 链接到错误的路径
【发布时间】:2020-06-18 15:58:22
【问题描述】:

我有一个 django 应用程序,主页路由正确,但是当我尝试单击任何链接时,我收到 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
}

【问题讨论】:

    标签: django nginx centos django-deployment


    【解决方案1】:

    我遵循了一个糟糕的教程,其中有一个错字。如果您碰巧遵循相同的类型,则应在您的 nginx 站点可用文件中放置:

    location /
    

    不是

    location = /
    

    https://www.shellvoide.com/hacks/installing-django-application-with-nginx-mysql-and-gunicorn-on-ubuntu-vps/

    【讨论】:

    • 我也是!同样的教程,同样的问题。感谢您在这里发布答案。我会联系网站上的开发人员并告诉他这是一个问题。
    猜你喜欢
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2013-11-05
    • 2021-10-28
    相关资源
    最近更新 更多