Article Title: sequence of multiple server_name for Nginx Virtual Hosts. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In Nginx + PHP + MediaWiki configuration, a problem was found: the Nginx virtual host where MediaWiki is located is bound to multiple domain names, but no matter what domain name is used to access the MediaWiki homepage, will be redirected to one of the domain names. The Nginx configuration file does not have relevant rewrite jump rules, so it should be a jump made by the PHP program of MediaWiki. However, after traversing all the files in the MediaWiki directory and querying every table in the MySQL database, no such domain name is found. Later, by checking the source code, we found that MediaWiki was based on the jump of $ _ SERVER ['server _ name'] and found the following problems:
In an Nginx virtual host, you can bind multiple server_name, for example:
The order of server_name is different. It may affect the use of $ _ SERVER ["SERVER_NAME"] Or getenv ('server _ name') in PHP programs to obtain SERVER domain names:
$ _ SERVER ["SERVER_NAME"] Or getenv ('server _ name') always gets the first domain NAME in the Nginx server_name configuration, which requires attention during program development. The first domain name is equivalent to ServerName in the Apache Virtual Host Configuration, and the domain name is equivalent to Apache ServerAlias.
Link: http://blog.s135.com/post/382.htm