Home  >  Q&A  >  body text

Can Nginx configure a 404 page to correspond to multiple domain names?

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;
}
我想大声告诉你我想大声告诉你2713 days ago505

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-05-16 17:23:04

    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.

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 17:23:04

    Try map

    //context http

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

    //context server

    error_page $page;

    reply
    0
  • Cancelreply