nginx 超时配置、根据域名、端口、链接 配置不同跳转

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

location的语法
已=开头表示精确匹配
如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。
^~ 开头表示uri以某个常规字符串开头,不是正则匹配
~ 开头表示区分大小写的正则匹配;
~* 开头表示不区分大小写的正则匹配
/ 通用匹配, 如果没有其它匹配,任何请求都会匹配到

 

根据域名判断跳转不同服务

复制代码
#当客户端访问www.a393060727.com,监听端口号为80,直接跳转到data/www目录下文件
    server {
        listen       80;
        server_name  www.a393060727.com;
        location / {
            root   data/www;
            index  index.html index.htm;
        }
    }
    #当客户端访问bbs.a393060727.com,监听端口号为80,直接跳转到data/bbs目录下文件
     server {
        listen       80;
        server_name  bbs.a393060727.com;
        location / {
            root   data/bbs;
            index  index.html index.htm;
        }
    }
复制代码

 

根据端口判断跳转不同服务

复制代码
#当客户端访问www.a393060727.com,监听端口号为8080,直接跳转到data/www目录下文件
     server {
        listen       8080;
        server_name  8080.a393060727.com;
        location / {
            root   data/www;
            index  index.html index.htm;
        }
    }
    
    #当客户端访问www.a393060727.com,监听端口号为8081,直接跳转到data/bbs目录下文件
     server {
        listen       8081;
        server_name  8081.a393060727.com;
        location / {
            root   data/bbs;
            index  index.html index.htm;
        }
    }
复制代码

 

根据链接不同,跳转不同地址服务器

复制代码
### 服务创建监听的端口号
    server {
      ##监听的端口号
        listen       80;
      ###  服务名称
        server_name  www.a393060727.com;
      #### 匹配URL路径地址 /表示匹配所有路径地址 默认不区分大小写
        ###location / {
           ### root   html;
            ### index  index.html index.htm;
       ### }
     ### 表示 /后面的路径地址不能带任何字符串     www.a393060727.com/userNamne
       ## location =/ {
         ###   root   html;
           ### index  index.html index.htm;
        ###}
        ### 匹配项目名称为tomcat_8080开头
       location /tomcat_8080/ {
       ###  配置反向代理
            proxy_pass http://127.0.0.1:8080/;
            index  index.html index.htm;
        }
       ### 匹配项目名称为tomcat_8081开头
         location /tomcat_8081/ {
       ###  配置反向代理
            proxy_pass http://127.0.0.1:8081/;
            index  index.html index.htm;
        }
    }
复制代码

 

posted on   陈惟鲜的博客  阅读(936)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示