nginx转发404给django
要设置图片缓存,所以图片都是经过nginx转的,
location /media/ { expires 7d; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; alias /home/djangoproject/media/; break; }
服务器上有些图片丢失了,因为经过nginx,就会显示
404 Not Found
nginx/1.4.6 (Ubuntu)
改进,先做一个404的转发page
在项目的url中加入
urlpatterns = patterns('', ....... url(r'^404page$', 'home.views.error404', name='404page'), .......
views中添加
def error404(request): return render(request, '404.html', locals())
在templates目录下写一个404.html页面
Django部分OK
然后改nginx.conf
在server下添加一行
error_page 404 = /404page;
就OK啦,
相关推荐
nginxs 2020-11-14
Guanjs0 2020-11-13
小木兮子 2020-11-11
yserver 2020-11-11
ssihc0 2020-11-11
windle 2020-11-10
HanksWang 2020-11-10
liuchen0 2020-11-10
Freshairx 2020-11-10
ccschan 2020-11-10
liwf 2020-11-10
Guanjs0 2020-11-09
AderStep 2020-11-09
zrtlin 2020-11-09
mqfcu 2020-11-10
windle 2020-10-29