我有一些虚拟主机设置nginx 0.8.53,可以按我的意愿工作.然而,由于对虚拟主机的nginx的"最匹配"我需要添加一个默认主机赶上那是不是为特定的虚拟主机的所有请求.我想缺省主机返回一个404页面,并没有说明我正在运行的nginx 0.8.53.
我认为这应该是这样的:
# The default server.
#
server {
listen 80 default_server;
server_name everythingelse;
# Everything is a 404
location / {
return 404;
}
error_page 404 /opt/local/html/404.html;
}
Run Code Online (Sandbox Code Playgroud)
但是,这仍然返回具有版本号默认nginx的404页..看来"回404"忽略"error_page"配置..
0x1*_*ene 29
这就是我在我的conf中所做的工作:
# The default server.
server {
listen 80 default_server;
server_name everythingelse;
error_page 404 /404.html;
# Everything is a 404
location / {
return 404; #return the code 404
}
# link the code to the file
location = /404.html {
#EDIT this line to make it match the folder where there is your errors page
#Dont forget to create 404.html in this folder
root /var/www/nginx/errors/;
}
}
Run Code Online (Sandbox Code Playgroud)
nginx 中很少有指令采用文件系统路径。你想要这样的东西:
# The default server.
server {
listen 80 default_server;
server_name everythingelse;
root /opt/local/html;
error_page 404 /404.html;
# Everything is a 404
location / {
return 404;
}
# EDIT: You may need this to prevent return 404; recursion
location = /404.html {
internal;
}
}
Run Code Online (Sandbox Code Playgroud)
将 error_page 指令向上移动到conf中调用return 404之前。
这应该有效:
# The default server.
#
server {
listen 80 default_server;
server_name everythingelse;
error_page 404 /error_docs/404.html;
# Everything is a 404
location / {
return 404;
}
# Custom Error Page
location /error_docs {
alias /opt/local/html/;
log_not_found off;
access_log off;
}
}
Run Code Online (Sandbox Code Playgroud)
这将为所有站点(服务器)使用相同的自定义站点。您需要添加错误文档位置。
http {
error_page 404 /error_docs/404.html;
...
# The default server.
#
server {
listen 80 default_server;
server_name everythingelse;
# Everything is a 404
location / {
return 404;
}
# Custom Error Page
location /error_docs {
alias /opt/local/html/;
log_not_found off;
access_log off;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
50825 次 |
| 最近记录: |