Nginx server_name configuration Combat nginx Reverse proxy nginx is what

Source: Internet
Author: User
Tags nginx reverse proxy
1 ) server_name directives are primarily used to configure name-based virtual hosts ( inside the http > server ), server_name The order in which the instructions are received after the request is:

1 . accuracy of server_name matches, for example:

server {

Listen 80;

Server_namessdr.infowww.ssdr.info;

...

}

2 . in * string starting with the wildcard character:

server {

Listen 80;

Server_name*.ssdr.info;

...

}

3 . in * A string that ends with a wildcard character:

server {

Listen 80;

server_name www.*;

...

}

4 . match Regular expression:

server {

Listen 80;

server_name~^ (?. +) \.howtocn\.org$;

...

}

Nginx will follow 1,2,3,4 the order of servername match, only one match will stop the search .

2 ) in a Server Configure multiple level two domain names for a single site in a block :

in the actual site directory structure, we usually create a separate directory for the site's level two domain name, and we can use regular captures to implement a Server To Configure multiple level two domain names in a block:

Server

{

Listen 80;

Server_Name ~^ (. +)? \.domain\.com$;

Index index.html;

if ($host = domain.com) {

rewrite ^ http://www.domain.com permanent;

}

root/data/wwwsite/domain.com/$/;

}

The directory structure of the site should be as follows:

/data/wwwsite/domain.com/www/

/data/wwwsite/domain.com/nginx/

This access www.domain.com when Root Directory is /data/wwwsite/domain.com/www/ , nginx.domain.com when the /data/wwwsite/domain.com/nginx/ , and so on.

back if The purpose of the statement is to domain.com REDIRECT the orientation to the www.domain.com , which resolves both the Web site's home directory access and the ability to add SEO in the www.domain.com 's domain weight.

3 ) Multiple regular expressions:

If you are in server_name With the regular, and the following Location The field also uses a regular match so that it cannot be used $ , $ such a reference, the workaround is to pass Set The directive assigns the value to a named variable:

Server

{

Listen 80;

Server_Name ~^ (. +)? \.howtocn\.org$;

Set $www _root $;

root/data/wwwsite/ssdr.info/$www _root/;

Location ~. *\.php?$ {

Fastcgi_pass 127.0.0.1:9000;

Fastcgi_index index.php;

Fastcgi_param script_filename/data/wwwsite/ssdr.info/$fastcgi _script_name;

Include Fastcgi_params;

}

}

The above describes the Nginx server_name configuration, including the server,nginx aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.