时间:2020-07-22来源:www.pcxitongcheng.com作者:电脑系统城
1 = #表示精确严格匹配,只有请求的url路径与后面的字符串完全相等时,才会命中。同时若这个查询匹配,将停止搜索并立即处理此请求。 2 ~ #表示该规则是使用正则定义的,且区分大小写; 3 ^~ #表示uri以某个常规字符串开头,匹配 URI 路径。且nginx不对url做编码,如请求为/static/20%/aa,可以被规则^~ /static/ /aa匹配到(注意是空格); 4 ~* #表示该规则是使用正则定义的,且不区分大小写; 5 / #用户所使用的代理(一般为浏览器);
1 $http_x_forwarded_for #通过代理服务器来记录客户端的ip地址; 2 $http_referer #记录用户是从哪个链接访问过来的。
1 [root@nginx01 ~]# vi /etc/nginx/conf.d/location.conf
2 server {
3 listen 80;
4 server_name location.linuxds.com;
5 access_log /var/log/nginx/location.access.log main;
6 error_log /var/log/nginx/location.error.log warn;
7 location = / {
8 add_header Content-Type text/plain;
9 return 200 'A';
10 # 精确匹配 / ,主机名后面不能带任何字符串
11 }
12 location = /login {
13 add_header Content-Type text/plain;
14 return 200 'B';
15 }
16 location ^~ /static/ {
17 add_header Content-Type text/plain;
18 return 200 'C';
19 # 匹配任何以 /static/ 开头的地址,匹配以后,不在往下检索正则,立即采用这一条。
20 }
21 location ^~ /static/files {
22 add_header Content-Type text/plain;
23 return 200 'D';
24 # 匹配任何以 /static/files 开头的地址,匹配以后,不在往下检索正则,立即采用这一条。
25 }
26 location ~ \.(gif|jpg|png|js|css|txt) {
27 add_header Content-Type text/plain;
28 return 200 'E';
29 }
30 location ~* \.txt$ {
31 add_header Content-Type text/plain;
32 return 200 'F';
33 # 匹配所有以 txt 结尾的请求
34 # 然而,所有请求 /static/ 下的txt会被 规则 C 处理,因为 ^~ 到达不了这一条正则。
35 }
36 location /image {
37 add_header Content-Type text/plain;
38 return 200 'G';
39 # 匹配任何以 /image/ 开头的地址,匹配符合以后,还要继续往下搜索;
40 # 只有后面的正则表达式没有匹配到时,这一条才会采用这一条。
41 }
42 location / {
43 add_header Content-Type text/plain;
44 return 200 'H';
45 # 因为所有的地址都以 / 开头,所以这条规则将匹配到所有请求。
46 # 但是正则和最长字符串会优先匹配。
47 }
48 }
1 [root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@nginx ~]# nginx -s reload #重载配置文件










2024-07-18
Centos 7 二进制安装配置 MariaDB数据库2024-07-18
Centos7默认firewalld防火墙使用命令大全2024-07-07
四种执行python系统命令的方法常用权限linux系统内有档案有三种身份 u:拥有者 g:群组 o:其他人这些身份对于文档常用的有下面权限:r:读权限,用户可以读取文档的内容,如用cat,more查看w:写权限,用户可以编辑文档x...
2024-07-07
然而,如果我们遵循通常的 WordPress 最佳实践,这些安全问题可以避免。在本篇中,我们会向你展示如何使用 WPSeku,一个 Linux 中的 WordPress 漏洞扫描器,它可以被用来找出你安装...
2024-07-03