Multi-server_name sequence of Nginx Virtual Hosts

Source: Internet
Author: User
Tags mediawiki
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.