Nginx configuration file:
User nginx;
Worker_processes 1; # Number of processes started (the number of processes is not as high as the number of processes is. Generally, the number of processes is equal to the number of CPUs. If the number of processes exceeds the number of CPUs, context switching will take a long time .)
Events {
Worker_connections 1024;
### Number of concurrent requests of a process
Nginx can be used as a Web server, nginx reverse proxy, and mail proxy.
Configure in the following line:
HTTP {
Include mime. types;
Default_type application/cetet-stream;
# Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
# '$ Status $ body_bytes_sent "$ http_referer "'
# '"$ Http_user_agent" "$ http_x_forwarded_for "';
# Remote_addr Client IP remote_user remote user time_local local time request the number of bytes sent by the user request Resource Status Code body_bytes_sent http_referer accessing the webpage source link http_user_agent browser type http_x_forwarded_for Cache Server Software
Access_log/var/log/nginx/access. Log main; log storage path, in the main format
Sendfile on;
Keepalive_timeout 65; Use keep connection
# Gzip on; compress webpages before sending them
Server {
Listen 80 default_server;
SERVER_NAME localhost; host name
# Charset koi8-r;
# Access_log logs/host. Access. Log main;
Location/{is the root directory of http: // 172.16.100.1/
Root/usr/share/nginx/html; relative path of the webpage file storage location, it is best to use absolute path
Index index.html index.htm; Home Page
}
Error_page 404/404 .html;
Location =/404.html {
Root/usr/share/nginx/html;
}
Format of listen configuration: (only settings can be made in server)
Listen address: Port [default [backlog = num | rcvbuf = size received cache size | sndbuf = size sent cache size | accept_filter = filter | deferred | bind | SSL port 443 only]
Listen 127.0.0.1: 8000;
Listen 127.0.0.1;
Listen 8000;
Listen *: 8000;
Listen localhost: 8000;
Location configuration format: (can only be set in server)
Location [= | ~ | ~ * | ^ ~ | @]/URL /{...}
= Exact match. The requested file must be specific.
~ ~ * Regular expression. The URL is a regular expression patter ~ Case Sensitive ~ * Case insensitive
^ ~ Do not use regular expressions. Only match characters one by one
@ Switch to another Proxy Server
Priority: = ^ ~ (~ ~ *)
Example:
= Match only/
Location = /{
# Matches the query/only.
[Configuration A]
}
/It can match the contained directory
Location /{
# Matches any query, since all queries begins with/, but regular expresions and any longer conventional blocks will be matched first.
[Configuration B]
}
^ ~ Match the starting directory of the URL definition later
Location ^ ~ /Images /{
# Matches any query beginning with/images/and halts searching, so regular expressions will not be checked.
[Configuration C]
}
~ * Regular Expression matching
Location ~ * \. (GIF | JPG | JPEG) $ {
# Matches any request ending in GIF, JPG, or JPEG. However, all requests to the/images/directory will be handled by configuration C.
[Configuration D]
}
Example requests:
*/--> Configuration
*/Documents/document.html --> Configuration B
*/Images1.gif --> Configuration C
*/Documents/1.jpg --> Configuration d
Alias sets the alias, which is defined in location
Syntax: alias file-path | directory-Path
Location /{
Root/spool/W3;
}
Location/BBS /{
Alias/spool/BBS /;
}
Index settings Home Page
If you do not have a home page when accessing Autoindex, all pages under this directory will be listed.
Location /{
Autoindex on;
}
Accessmodule Access Control List
Location /{
Deny 192.168.1.1;
Allow 192.168.1.0/24;
Allow 10.1.0.0/16;
Deny all;
}
Enable nginx status monitoring;
Location/nginx status {
Stub_status on;
Access_log off; Disable access logs
}
Active connections: 2 active connections
Server accepts handled requests
125202 125202 125254
(Number of connections that have been accessed and processed in progress)
Reading: 1 writing: 1 waiting: 0
(The Read Request Header processes the request and sends the result to the number of connections that are still in the active state on the client)
Start user-based authentication:
Server {
SERVER_NAME www.magedu.com;
...
Location /{
Auth_basic "restricted ";
Auth_basic_user_file/etc/nginx/. htpasswd;
...
}
}
# Htpasswd-CM/etc/nginx/. htpasswd Jerry
This article is from the "O & M work notes" blog, please be sure to keep this source http://yyyummy.blog.51cto.com/8842100/1433093