Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何生成用户定义的“;404找不到页面“;在nginx?_Python_Django_Nginx_Gunicorn - Fatal编程技术网

Python 如何生成用户定义的“;404找不到页面“;在nginx?

Python 如何生成用户定义的“;404找不到页面“;在nginx?,python,django,nginx,gunicorn,Python,Django,Nginx,Gunicorn,我已经在我的nginx服务器上部署了一个带有gunicorn的django示例项目,当用户输入错误的url时,我需要显示我自己的404页面未找到html页面 server { listen localhost:8899; root /home/mulagala/Desktop/projects/28-05-2014/mysite/mysite/templates access_log /var/log/nginx/example.log; error_log /var/log/nginx/ex

我已经在我的nginx服务器上部署了一个带有gunicorn的django示例项目,当用户输入错误的url时,我需要显示我自己的
404页面未找到
html页面

server {
listen localhost:8899;
root /home/mulagala/Desktop/projects/28-05-2014/mysite/mysite/templates
access_log  /var/log/nginx/example.log;
error_log /var/log/nginx/example.error.log;

location / {
    proxy_pass http://127.0.0.1:8060;
}

# redirect server error pages to the static page /40x.html
#
  error_page  404              /404.html;
  location  = /404.html {
    }

# redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }


location /static/ {
    autoindex on;
    alias /home/mulagala/Desktop/projects/28-05-2014/mysite/static/;
}
} 

但当我输入错误的url时,仍然会收到django默认消息
未找到页面(404)
,并显示我所有的url。我是否需要更改django项目中的任何内容或任何其他内容。我犯了什么错误。如果您需要任何帮助,我们将不胜感激。您不需要此
错误\u第404页
块,并确保您已关闭
代理\u拦截\u错误。如果满足这两个条件,nginx将让应用程序(这里是Django)返回自己的404页面

此配置文件应该可以:

server {
    listen localhost:8899;
    root /home/mulagala/Desktop/projects/28-05-2014/mysite/;
    access_log /var/log/nginx/example.log;
    error_log /var/log/nginx/example.error.log;

    location / {
        proxy_pass http://127.0.0.1:8060;
    }

    location /static/ {
        autoindex on;
        alias /home/mulagala/Desktop/projects/28-05-2014/mysite/static/;
    }
} 

你在templates目录中创建了自己的404.html吗?@Josh是的,我创建了created@Mulagala您的
根指令在哪里?nginx应该如何知道在哪里查找404.html?@AlexeyTen,是的,我在发布问题后放置了,但结果仍然相同。我在哪里可以找到
代理截获\u错误
,我正在使用
gunicorn
@Mulagala运行我的应用程序。默认情况下,它设置为
关闭
。如果您没有修改nginx全局配置,没有也可以。我就像您说的那样,如果它由django处理,我们应该在设置文件中放置
DEBUG=False
。如果我这样做,我得到的是
错误请求(400)
@Mixime-Lorant,谢谢,我已经通过处理
错误请求400
解决了我的问题。我的404页面现在正在呈现