一:nginx 基礎教程
https://www.runoob.com/w3cnote/nginx-setup-intro.html
nginx 負載均衡配置,和啓動,停止,檢查配置文件命令
https://blog.csdn.net/weixin_43452871/article/details/89072086
二:nginx 正則配置
對這些不同前綴,分下類,就2 大類:
正則location ,英文說法是location using regular expressions
普通location ,英文說法是location using literal strings 。
那麼其中“~ ”和“~* ”前綴表示正則location ,“~ ”區分大小寫,“~* ”不區分大小寫;
其他前綴(包括:“=”,“^~ ”和“@ ”)和 無任何前綴 都屬於普通location 。
詳細說明:
~ 區分大小寫匹配
~* 不區分大小寫匹配
!~ 區分大小寫不匹配
!~* 不區分大小寫不匹配
^ 以什麼開頭的匹配
$ 以什麼結尾的匹配
* 代表任意字符
1.“=” 精確匹配
內容要同表達式完全一致才匹配成功
例1:location =/text.html { #精準匹配,瀏覽器輸入IP地址/text.html,定位到服務器/var/www/html/text.html文件
root /var/www/html;
index text.html;
}例2:location = / {
.....
}
# 只匹配http://abc.com
# http://abc.com [匹配成功]
# http://abc.com/index [匹配失敗]
2. “~”,大小寫敏感
例1:location ~ image { #正則匹配,瀏覽器輸入IP/image..地址會被命中,定位到/var/www/image/index.html
root /var/www/image;
index index.html;
}location ~ /Example/ {
.....
}
#http://abc.com/Example/ [匹配成功]
#http://abc.com/example/ [匹配失敗]
3.“~*”,大小寫忽略
例1:location ~* /Example/ {
.....
}
# 則會忽略 uri 部分的大小寫
#http://abc.com/test/Example/ [匹配成功]
#http://abc.com/example/ [匹配成功]例2:location ^~ /images/ { configuration C }
# 匹配任何以/images/開頭的查詢並且停止搜索。任何正則表達式將不會被測試。
location ~* .(gif|jpg|jpeg)$ { configuration D }# 匹配任何已.gif、.jpg 或 .jpeg 結尾的請求,但是 所有 /images/開頭的請求 會匹配到 configuration C
4.“^~”,只匹配以 uri 開頭
location ^~ /index/ {
.....
}
#以 /img/ 開頭的請求,都會匹配上
#http://abc.com/index/index.page [匹配成功]
#http://abc.com/error/error.page [匹配失敗]
5.“@”,nginx內部跳轉
location /index/ {
error_page 404 @index_error;
}
location @index_error {
.....
}
#以 /index/ 開頭的請求,如果鏈接的狀態爲 404。則會匹配到 @index_error 這條規則上。location @named { configuration E }
#它是專門用來處理“內部重定向(internally redirected )
6 不加任何規則
不加任何規則則時,默認是大小寫敏感,前綴匹配,相當於加了“~”與“^~”
只有 / 表示匹配所有uri
例1:location / { #普通匹配,瀏覽器輸入IP地址,定位到服務器/usr/local/nginx/html/default.html文件
root html;
index default.html;
}location /index/ {
......
}
#http://abc.com/index [匹配成功]
#http://abc.com/index/index.page [匹配成功]
#http://abc.com/test/index [匹配失敗]
#http://abc.com/Index [匹配失敗]