The meaning and usage of some of the directives for global segments, events, and HTTP segments are listed in the 2nd article above, which describes the instructions for the server segment.
Listen
The Listen directive has three configuration methods:
1, listen address[:p ort] [default_server] [SSL];
2, listen port [default_server] [SSL];
3, listen Unix:path [Default_server] [SSL];
Examples of Use:
Listen *:80 | *:8000; # # #监听所有80和8000端口
Listen 192.168.1.10;## #监听具体IP的所有端口上的连接
Listen 8000;## #监听具体端口上的所有IP连接, equivalent to listen *:8000;
SERVER_NAME:
Syntax: server_name name ...;
Set the virtual host name. You can set multiple name, for example:
server_name myserver.com www.myserver.com;
The wildcard character * can be used in name, but the wildcard character can only be used in the first or trailing segment of a name consisting of three-segment strings, or as a trailing segment of a name consisting of two-segment strings. For example:
server_name *.myserver.com www.myserver.*;
You can also use a regular expression in name and use the tilde "~" as the opening tag for the regular expression string. For example:
server_name ~^www\d+\.myserver\.com$;
Represents a name that begins with the match www, followed by one or more digits, followed by MyServer, and terminated with COM
Because the server_name directive supports the way that wildcard wildcards regular expressions are configured, in a configuration file that contains multiple virtual hosts, a name may appear that has been successfully matched server_name by multiple virtual hosts. So what is the virtual host processing the request from this name? Nginx chooses the virtual host to respond to the client's request based on the following priority:
1, accurate matching server_name
2. Match server_name successfully at start of on
3, wildcard at the end of the match server_name success
4. Regular expression Matching server_name success
5. If server_name is matched to a match of the same priority, then who will first match to who is responsible for the response.
Root
Syntax: root path;
Specifies the root directory path.
Example:
location/data/{
root/wwwroot/html;
}
When the location receives a "/data/index.html" Access request, the index.html is found in the/wwwroot/html/data/directory in response to the user request.
Index:
Set the default home page, there are generally two functions, one is, the user in the request to visit the site, the request address can not write the first page name, two, can be a request, according to the content of its request to set the home page, the instruction syntax structure is:
Index file ...;
Example:
server {Listen 80; server_name test; Error_log/etc/nginx/conf.d/error.log; root/wwwroot/html; Index c.html; location/t/{root/wwwroot/html; Index a.html; }}
Error_page:
To set the site's error page, the syntax is:
Error_page code ... [=[response]]uri;
Code: HTTP error Codes to process
Response: Converts code-specified error codes to new error codes
URI: The path to the error page or the site address, which is relative to the root path of the root setting.
Example:
Error_page 404/404.html;
IP-based access control :
Allow Address | CIDR | Unix |all;
Set the IP range allowed for access
Deny Address | CIDR | unix:| all;
Set IP range for access denied
Example:
location/t/{root/data/www/vhost2/; Allow 172.16.100.120; Deny all;}
Allow only 172.16.100.120 this IP address to access
Access Nginx server based on account password
Auth_basic String | Off
Whether to enable password authentication
Auth_basic_user_file file;
Specifies the profile path for password authentication, which is valid only when Auth_basic is enabled.
Example: Create a server.conf configuration file and set up an account password to access the virtual host configured in that server
1. Create the server.conf configuration file first
#cd/etc/nginx/conf.d/
#vim server.conf
server {Listen 8888; server_name test; root/wwwroot/html; location/t/{auth_basic "Admin area"; AUTH_BASIC_USER_FILE/ETC/NGINX/.NGXPASSWD; }}
2, create the account password file, need to install httpd
#htpasswd-C-m/etc/nginx/.ngxpasswd Tom
Create a password file, the path is/ETC/NGINX/.NGXPASSWD and create a Tom account, the command will prompt for a password
#htpasswd-M/etc/nginx/.ngxpasswd Jerry
Create an account named Jerry and do not use the-C option when creating a second account
3. Test Visit website
http://test:8888/t/a.html prompt to enter account password
Stub_status:
Through the development of the URI output Stub_status, can only be defined in the server and location.
Example:
server {Listen 8889; server_name test; root/wwwroot/html; location/t/{stub_status; } }
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7F/AD/wKiom1coapbhM6ZAAABC07Y4yeI228.png "title=" 111. PNG "alt=" Wkiom1coapbhm6zaaabc07y4yei228.png "/>
Current active client connections include clients with waiting status
Accepts: Total number of client connections accepted
Handled: Number of client connections processed
Requests: Total number of client requests
Reading: Current Nginx is reading the number of connections to the client request message
Writing: Number of connections that are responding to client request messages
Waiting: The number of idle connections waiting for it to make a request
This article from "Zengestudy" blog, declined reprint!
3, nginx about the configuration of the server segment