Can Nginx configure a 404 page to correspond to multiple domain names?
我想大声告诉你
我想大声告诉你 2017-05-16 17:21:04
0
2
502

As in the title:

There is only one

server in nginx. All domain names are configured the same. Through the program, each domain name is an independent site. If you want each domain name to display its own 404 page when 404 occurs, , I don’t know how to configure and implement it under nginx

server {
    ...
    server_name a.com b.cn d.org ....; # 配置了很多域名
    ...
    
    error_page 404 /404.html;
}
我想大声告诉你
我想大声告诉你

reply all(2)
小葫芦

Just move the following to the http scope. Don’t write one in each server
error_page 404 /404.html;

If you encounter this kind of problem, you should read the documentation:
Syntax: error_page code ... [=[response]] uri;
Default: —
Context: http, server, location, if in location

context represents the scope of this error_page syntax, indicating that it can be placed in http.

滿天的星座

Try map

//context http

map $http_host $page {
    default  404.html;
    .com   404.com.html;
    .cn 404.cn.html;

}

//context server

error_page $page;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!