2, nginx的location 詳解
阿新 • • 發佈:2020-07-25
= :精確匹配(必須全部相等) ~ :大小寫敏感 ~* :忽略大小寫 ^~ :只需匹配uri部分,不匹配正則表示式。 @ :內部服務跳轉 匹配順序: = > ^~ > ~* > /document/ > / request / :A request /index.html :B request /documents/document.html :C request /images/1.gif :D request /documents/1.jpg :E [root@centos7 nginx]# cat nginx.conf worker_processes 2; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.etiantian.org; index index.html index.htm; location = / { return 500; } location / { return 300; } location /documents/ { return 200; } location ^~ /images/ { return 201; } location ~* \.(gif|jpg|jpeg)$ { return 100; } } } [root@centos7 nginx]# [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1 500 [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1/ 500 [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1/index.html 300 [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1/documents/document.html 200 [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1/images/1.gif 201 [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1/documents/1.jpg 100 [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1/www/index.html 300 [root@centos7 nginx]# curl -o /dev/null -s -w "%{http_code}\n" 127.0.0.1/www/index.html/ 300 [root@centos7 nginx]#