【问题标题】:nginx+uwsgi+django, how to configure 404.html and 502.htmlnginx+uwsgi+django,如何配置404.html和502.html
【发布时间】:2012-09-28 12:29:00
【问题描述】:

我关闭调试模式,当我访问非退出页面时看到默认的 502 错误。

我已经在我的项目中放了404.html, 403.html, 502.html,但是我还是看不到这些页面,项目除了这部分都运行良好,我应该如何配置这个问题?

我的配置如下:

server{
listen 80;
server_name 119.254.35.221;
location /{
uwsgi_pass 127.0.0.1:8000;
include uwsgi_params;
uwsgi_param UWSGI_SCRIPT www.wsgi;
uwsgi_param UWSGI_CHDIR /root/www;
uwsgi_param UWSGI_PYHOME /root/www;
uwsgi_param SCRIPT_NAME "";
}
}

项目树:

[root@vps616 www]# pwd
/root/www
[root@vps616 www]# ll
total 1036
drwxr-xr-x 2 root root    4096 Sep 28 11:05 books
-rwxr-xr-x 1 root root     246 Sep 27 13:29 manage.py
-rw------- 1 root root    6228 Sep 28 09:56 nohup.out
-rwxr-xr-x 1 root root      41 Sep 27 23:54 restart.sh
-rwxr-xr-x 1 root root      53 Sep 28 16:51 start.sh
drwxr-xr-x 2 root root    4096 Sep 28 20:18 static
-rw-rw-rw- 1 root root     217 Sep 28 14:05 uwsgi.ini
-rw-r--r-- 1 root root     272 Sep 27 23:16 uwsgi.xml.backup
drwxr-xr-x 3 root root    4096 Sep 28 20:27 www
-rw-r----- 1 root root 1009290 Sep 28 20:25 www.log
-rw-rw-rw- 1 root root       6 Sep 28 16:48 www.pid
[root@vps616 www]# ll www
total 48
-rw-r--r-- 1 root root    0 Sep 28 20:27 403.html
-rw-r--r-- 1 root root    0 Sep 28 20:18 404.html
-rw-r--r-- 1 root root  227 Sep 28 17:01 forms.py
-rw-r--r-- 1 root root    0 Sep 27 13:29 __init__.py
-rw-r--r-- 1 root root  112 Sep 28 08:46 __init__.pyc
-rw-r--r-- 1 root root 5247 Sep 28 20:20 settings.py
-rw-r--r-- 1 root root 2924 Sep 28 20:20 settings.pyc
drwxr-xr-x 2 root root 4096 Sep 28 17:04 templates
-rw-r--r-- 1 root root  630 Sep 28 16:47 urls.py
-rw-r--r-- 1 root root  641 Sep 28 11:03 urls.pyc
-rw-r--r-- 1 root root  625 Sep 28 17:22 views.py
-rw-r--r-- 1 root root  871 Sep 28 11:03 views.pyc
-rw-r--r-- 1 root root 1126 Sep 28 12:32 wsgi.py
-rw-r--r-- 1 root root 1000 Sep 28 12:32 wsgi.pyc
[root@vps616 www]# 

uwsgi 配置:

[root@vps616 www]# cat uwsgi.ini 
[uwsgi]  
uid = 500
listen=200
master = true  
profiler = true 
processes = 8 
logdate = true  
pidfile = /root/www/www.pid  
daemonize = /root/www/www.log  
enable-threads = true
memory-report = true
limit-as = 6048

启动命令:

uwsgi --ini uwsgi.ini -s 127.0.0.1:8000

非常感谢。

【问题讨论】:

  • 你真正想展示的东西是什么?

标签: python django nginx uwsgi


【解决方案1】:

尝试将 404.html 等文件移动到您的模板目录中(如果您有 base_site.html)

【讨论】:

  • 另一个问题是:如何配置nginx在/root/www/static中显示静态文件,非常感谢,在这里等待..
  • 请举个例子,为什么要显示静态文件?哪种静态文件? django 项目中的静态目录通常包含静态资源,如 css、javascript、图像......我在 nginx 配置的服务器部分使用它: location /static { root /abs/path/to/the/web/root/;最大过期;重要的部分是根....,很明显,我将所有静态文件都收集在一个静态目录中,该目录完全位于网站的 web 根目录中。
  • 我也把静态文件放在了nginx本身,配置是这样的,但是我发现http请求是到uwsgi而不是nginx本身,我犯了什么错误?谢谢..server{听80;服务器名称 119.254.35.221;位置 ^~ /static { 根 /root/www; } 位置 /{ uwsgi_pass 127.0.0.1:8000;包括 uwsgi_params; uwsgi_param UWSGI_SCRIPT www.wsgi; uwsgi_param UWSGI_CHDIR /root/www; uwsgi_param UWSGI_PYHOME /root/www; uwsgi_param SCRIPT_NAME ""; } }
  • 和 nginx 访问日志是:2012/09/28 21:32:23 [error] 19969#0: *24 open() "/root/www/static/aa.html" failed , uri 是正确的,但它转到位置 /,而不是 /static/xxx
  • 这是我使用的虚拟主机配置的一部分:pastebin.com/hwpDj50B你使用这个(位置^~ /static),尝试只使用位置/静态...
猜你喜欢
  • 2020-01-23
  • 2017-06-23
  • 2016-02-16
  • 2012-07-10
  • 2019-01-01
  • 2015-02-19
  • 2020-06-29
  • 2011-06-26
  • 2016-04-20
相关资源
最近更新 更多