nginx自定义错误页面502与CSS和图像文件 [英] nginx custom error page 502 with css and image files
问题描述
我试图为503添加一个自定义错误页面。我做的是。将下面的行添加到nginx.conf文件中的server conf。
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root / home / username / sites / myProject / current / errorPages;
内部;
}
它显示自定义页面当uwsgi发生故障时,然而这并不怎么影响。我试图做许多我能想到的配置,但没有运气。有谁知道我可以如何显示图像文件并启用自定义错误页的CSS?
我把自定义错误页面放到/ home / username / sites / myProject / current / errorPages
中,文件结构是..
errorPages / 50x.html
errorPages / 50x_files / 50x.css
errorPages / 50x_files / 50x.js
errorPages /50x_files/image.png
问题,并且工作是如何设置nginx conf:
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root / home / username / sites / myProject / current / errorPages;
}
location = /image.png {
root / home / username / sites / myProject / current / errorPages / 50x_files;
}
然后将图片简单地引用为src =image.png。同样应该适用于你的css和js!
编辑:我找到了一种方法使它适用于一堆文件:
error_page 500 502 503 504 /errorPages/50x.html;
location / errorPages / {
root / home / username / sites / myProject / current /;
}
这样errorPages文件夹中的所有文件都可用(例如src = /errorPages/image.png),因为nginx会尝试匹配所有的/ errorPages / ...。有必要在位置(因为它不再是完全匹配)和内部之后删除=。 (因为其他资源将从html中调用,而不是由nginx内部调用)。
I'm trying to add a custom error page for 503. what I did is. adding below lines to server conf in nginx.conf file.
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/username/sites/myProject/current/errorPages;
internal;
}
It displays the custom page when uwsgi is down, however this doesn't how any images. I was trying to do many config I can think of, but no luck. Does anybody know how I can display image file and enable css for a custom error page?
I put my custom error page into /home/username/sites/myProject/current/errorPages and file structure is..
errorPages/50x.html
errorPages/50x_files/50x.css
errorPages/50x_files/50x.js
errorPages/50x_files/image.png
I just had the same problem, and what did work is setting the nginx conf like this :
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/username/sites/myProject/current/errorPages;
}
location = /image.png {
root /home/username/sites/myProject/current/errorPages/50x_files;
}
And then reference the image simply as src="image.png". The same should apply to your css and js!
Edit : I find a way to make it work for a bunch of file:
error_page 500 502 503 504 /errorPages/50x.html;
location /errorPages/ {
root /home/username/sites/myProject/current/;
}
This way all the files in the errorPages folder will be available (e.g. src="/errorPages/image.png"), as nginx will try to match all "/errorPages/...". It is necessary to remove both the "=" after "location" (as it's not an exact match anymore) and the "internal;" in it (as the other resources will be called from the html and not internally by nginx).
这篇关于nginx自定义错误页面502与CSS和图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!