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;
        }
    }
原文地址:https://www.cnblogs.com/a393060727/p/12041449.html