location的作用

location指令的作用是根据用户请求的URI来执行不同的应用,也就是根据用户请求的网站URL进行匹配,匹配成功即进行相关的操作。

location的语法

已=开头表示精确匹配
如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。

^~ 开头表示uri以某个常规字符串开头,不是正则匹配

~ 开头表示区分大小写的正则匹配;

~* 开头表示不区分大小写的正则匹配

/ 通用匹配, 如果没有其它匹配,任何请求都会匹配到

server {

listen       80;

server_name  www.toov5.com;

location =/ {     #精确匹配,注解后面不能带任何字符   匹配所有 /            有等于号 “”=“”

proxy_pass http://127.0.0.1:8080;

index  index.html index.htm;

}

}

 传说中的API设计!

#匹配所有以/开头请求

server {
listen 80;
server_name www.toov5.com;
#匹配所有以/开头请求
location / {          #没有等于号!!!  “”=“”
proxy_pass http://127.0.0.1:8080;
index index.html index.htm;
}
}

###  以开头/toov5_8080拦截  默认开启不区分大小写     一个server两个location哦!

server {
listen 80;
server_name www.toov5.com;
### 以开头/toov5_8080 最终跳转到http://127.0.0.1:8080/;
location / toov5_8080/ {
proxy_pass http://127.0.0.1:8080/;
index index.html index.htm;
}
### 以开头/toov5_8081 最终跳转到http://127.0.0.1:8081/;
location /toov5_8081/ {
proxy_pass http://127.0.0.1:8081/;
index index.html index.htm;
}
}

目前用到的就这几个 正则表达式  后面遇到别的继续积累增加~ 未完待续~

pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.toov5.proxyNginx</groupId>
<artifactId>proxyNginx</artifactId>
<version>0.0.1-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency> </dependencies>
</project>

 yml

server:
port: 8081  

 后台

package NginxTest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class IndexController {
@Value("${server.port}")
private String port;
@RequestMapping("/")
public String index(){
return port;
}
}

启动类

package NginxTest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class app {
public static void main(String[] args) {
SpringApplication.run(app.class, args);
}
}

运行:

Nginx的Location正则表达式的更多相关文章

  1. nginx:location指令中的正则表达式

    nginx:location指令中的正则表达式 uri匹配步骤 官网说明https://docs.nginx.com/nginx/admin-guide/web-server/web-server/ ...

  2. nginx Location正则表达式

    1. Location正则表达式 1.1. location的作用 location指令的作用是根据用户请求的URI来执行不同的应用,也就是根据用户请求的网站URL进行匹配,匹配成功即进行相关的操作. ...

  3. rewrite规则写法及nginx配置location总结

    rewrite只能放在server{},location{},if{}中,并且只能对域名后边的除去传递的参数外的字符串起作用. 例如http://seanlook.com/a/we/index.php ...

  4. Nginx之location 匹配规则详解

    有些童鞋的误区 1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通, ...

  5. Nginx 的 Location 配置指令块

    最近一段时间在学习 Nginx ,以前一直对 Nginx 的 Location 配置很头大,最近终于弄出点眉目.总结如下:nginx 配置文件,自下到上分为三种层次分明的结构: |    http b ...

  6. 快速掌握Nginx(二) —— Nginx的Location和Rewrite

    1 location详解 1.location匹配规则 Nginx中location的作用是根据Url来决定怎么处理用户请求(转发请求给其他服务器处理或者查找本地文件进行处理).location支持正 ...

  7. Nginx的location匹配规则

    一 Nginx的location语法 location [=|~|~*|^~] /uri/ { … } =         严格匹配.如果请求匹配这个location,那么将停止搜索并立即处理此请求 ...

  8. Nginx的location配置规则梳理

    Nginx几乎是当下绝大多数公司在用的web应用服务,熟悉Nginx的配置,对于我们日常的运维工作是至关重要的,下面就Nginx的location配置进行梳理: 1)location匹配的是nginx ...

  9. Nginx 配置 Location 规则优先级问题

    nginx 的 location与配置中 location 顺序没有关系,与 location 表达式的类型有关.相同类型的表达式,字符串长的会优先匹配. 以下是按优先级排列说明: 等号类型(=)的优 ...

随机推荐

  1. javascript --- 继承小结

    回顾之前学到的知识,大体上可以分为两类: 1. 基于构造器工作的模式. 2. 基于对象的工作模式. 3. 是否使用原型 4. 是否执行属性拷贝. 5. 两者都有(执行原型属性拷贝) 下面我们把之前的知 ...

  2. 提高在Xcode上的工作效率

    对于在Xcode上提高工作效率,内功在这不提,对于外力,我将它分为三类: 工具.快捷键和小技巧.主要获得的路径是通过平时积累和看 WWDC12 上的 Session 402:Working Effic ...

  3. SharePreferences使用

    获取数据: @SuppressLint("InlinedApi") private String getFromSharePreference(String key) { if ( ...

  4. Scala IDE里的WorkSheet的使用

    所见即所得的一个工具, 左边编码,右边立即出结果 https://www.cnblogs.com/zlslch/p/6115118.html

  5. Git 的使用Git Bash和Git GUI

    使用Github也有一年的时间了,之前一直都是使用的Github客户端,对提交,更新,克隆,合并,分支有一定的了解和实践.一直都想试试命令行的形式,但是感觉可能桌面版的方便就没有做. 可是Github ...

  6. 使用c#訪问Access数据库时,提示找不到可安装的 ISAM

    使用c#訪问Access数据库时,提示找不到可安装的 ISAM.例如以下图: 代码例如以下: connectionString = "Provider=Microsoft.Jet.OLEDB ...

  7. 【Python】输出程序运行的百分比

    对于一些大型的Python程序.我们须要在命令行输出其百分比,显得更加友好,以免被人误会程序陷入死循环.假死的窗口. 关键是利用到不换行的输出符\r,\r的输出.将直接覆盖掉此行的内容. 比方例如以下 ...

  8. redirect_uri 參数错误的解决的方法

    我通过java代码去获得用户的openid,一直报redirect_uri. 我页面代码的链接为: https://open.weixin.qq.com/connect/oauth2/authoriz ...

  9. HDU 3564 Another LIS splay(水

    题意: 给定一个空序列 插入n个数(依次插入 1.2.3.4··n) 以下n个数表示i插在哪个位置. 每插入一个数后输出这个序列的lis 然后... 由于每次插入的数都是当前序列最大的数 所以不会影响 ...

  10. FPGA机器学习之机器学习的n中算法总结1

    机器学习是AI领域的重要一门学科.前面我描写叙述过.我计划从事的方向是视觉相关的机器学习分类识别,所以可能在每一个算法的分析中,仅仅增加在视频.视觉领域的作用. 我毛华望QQ849886241.技术博 ...