1. Basic Configuration
Worker_processes auto|3; Specifies the number of cores to use, the default auto, or the typical self-core number-1, which can be lscpu to view
Events {
Worker_connections 1024; Maximum concurrent connections, maximum concurrent responses worker_processes * Worker_connections
}
HTTP {
Keepalived_timeout 65 0 means no long connection
Keepalived_request Long Connection maximum number of resources, default 100
Keepalived_disable None|browser
server {
Listen 127.0.0.1:80 default_server default virtual host
server_name www.magedu.com
Match priority, exact-left match-right match-regular match
Www.magedu.com
*.magedu.com
Www.magedu.*
~^.*\.magedu\. *$
Root/usr/share/nginx/html
Location/{
}
match priority, exact-left match-regular match-without symbol
= Precise
^~ left Match
~ Regular match, case sensitive
~* regular match, case insensitive
Error_page 404/404.html;
location=/40x.html{
}
}
}
2. Status page
Location/status {
Stub_status;
}
Active connections Active Client link count
Accepts total number of client links received
Handled total number of client requests processed
Requests total number of requests
Total number of request-handled rejected
The number of Reading in the header of the Read client message
Writing number of response messages sent
Walting is in an idle connection waiting for the client to make a request, and the value may be
KeepAlive Timeout set too long
3. Prevent hotlinking
Location ~* \. (gif|jpg|png|bmp) $ {
Valid_referers None blocked *.magedu.com server_names ~\.google\. ~\.baidu\.;
if ($invalid _referer) {
return 403;
}
}
4.php-fpm
Location ~ \.php$ {
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Fastcgi_param script_filename $document _root $fastcgi _script_name;
Include Fastcgi_params;
}
5. Static and dynamic separation
Location/{
Proxy_pass http://192.168.1.11;
}
Location ~ \.php${
Proxy_pass http://192.168.1.12;
}
6. Load Balancing
Upstream Backend {
Server 192.168.1.11 weight=1;
Server 192.168.1.12 weight=1;
Ip_hash equivalent to SH | Least_conn minimum link;
Down Manually marking the Downline
Backup 192.168.1.13; Equivalent to sorry server
}
Location/{
Proxy_pass Http://backend;
}
Linux self-study note--nginx Basic configuration