location~*\.(mp4|avi|gif)${return200205;}location~\.(jpg|JPEG|gif)${return200206;} 上面的两个例子中,~* 表示忽略大小写,~ 表示区分大小写。我们可以直接这样来测试,http://192.168.56.88/1.mp4 和 http://192.168.56.88/1.MP4 都是走的 205 ,http://192.168.56.88/1.JPEG 走的是 206 ,但 ht...
location是有顺序的,当一个请求有可能匹配多个location时,实际上这个请求会被第一个location处理 匹配所有请求 如果前面没有任何可以匹配的location,那么“/”这个location会进行处理,其会匹配所有的http请求 一般将这个location放在最后 location / { # 可以匹配所有请求 } 1. 2. 3. location配置块的嵌套 除了以下前...
Nginx 中的 Location 指令 是NginxHttpCoreModule中重要指令。Location 指令比较简单,但却是配置 Nginx 过程中不得不去了解的。 Location 指令,是用来为匹配的 URI 进行配置,URI 即语法中的”/uri/”,可以是字符串或正则表达式。但如果要使用正则表达式,则必须指定前缀。 一、基本语法 location [=|~|...
然而,所有请求 /images/ 下的图片会被 location ^~ /images/ 处理,因为 ^~ 的优先级更高,所以到达不了这一条正则 (7)location /images/abc {} 最长字符匹配到 /images/abc,优先级最低,继续往下搜索其它 location,会发现 ^~ 和 ~ 存在 (8)location ~ /images/abc {} 匹配以/images/abc 开头的,优先...
location / { proxy_pass http://127.0.0.1:8080; index index.html index.htm; } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 以开头/hao_8080拦截 默认开启不区分大小写 在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对路径,则nginx不会把location中匹配的路径部分加入代理uri;如果没有/,则...
location = /50x.html { root html; } } } 可以看到,nginx.conf配置文件由3部分组成: main块 events块 http块。http块中可以配置多个server块,每个server块中可以配置多个location块。 接下来我们来分别看看这三大块可以进行哪些配置。由于可配置项的数量很多,我们仅列举出常用的配置选项,具体可见官方文档: ...
http { server { listen 80; # 监听80端口 server_name localhost; # 服务器名称 # 文档的根目录 root /usr/share/nginx/html; # 默认请求 location / { index index.html index.htm; } # 404错误页面 error_page 404 /404.html; location = /40x....
nginx -redirect隐藏http信息中location部分信息server { listen 80; server_name www.boke.com; location / { proxy_pass http://192.168.3.3:8080; proxy_redirect off;
location ~*hello\.(do|jsp)$ { echo "正则匹配: hello.(do|jsp)$ "; } 在浏览器中给Nginx发送http://localhost/1/2/hellp.do的请求地址,输出的结果是由配置在前面的location输出的。 4. 默认根路径匹配 根路径的路径规则就是使用单个“/”符号,示例如下: ...