首页 > 其他 > 详细

2, nginx的location 详解

时间:2020-07-25 22:15:50      阅读:84      评论:0      收藏:0      [点我收藏+]
	=  :精确匹配(必须全部相等)
    ~  :大小写敏感
    ~* :忽略大小写
    ^~ :只需匹配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]#

  

2, nginx的location 详解

原文:https://www.cnblogs.com/k8s-pod/p/13377657.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!