数据库地址转发

stream {
    upstream cloudsocket {
       hash $remote_addr consistent;
       server 192.168.100.20:3306 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 33060;#数据库服务器监听端口
       proxy_connect_timeout 10s;
       proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
       proxy_pass cloudsocket;
    }
}

proxy_pass配置

1.proxy_pass http://127.0.0.1:8080; 后面8080有 “/”

server {
        listen      80;
        server_name www.test.com;
        
        # 当访问 http://test.yeguxin.top/proxy/aaa/bbb.text时,nginx匹配到 /proxy/路径,把请求转发给127.0.0.1:8080服务.
        # 实际请求代理服务器路径为 " 127.0.0.1:8080/aaa/bbb.text "
        location /proxy/ {
             proxy_pass http://127.0.0.1:8080/;
        }
    }

2. proxy_pass http://127.0.0.1:8080; 后面8080没有 “/”

 server {
        listen      80;
        server_name www.test.com;
        
        # 当访问 http://test.yeguxin.top/proxy/aaa/bbb.text时,nginx匹配到 /proxy/路径,把请求转发给127.0.0.1:8080服务.
        # 实际请求代理服务器路径为 " 127.0.0.1:8080/proxy/aaa/bbb.text "
        location /proxy/ {
             proxy_pass http://127.0.0.1:8080;
        }
    }

3. proxy_pass http://127.0.0.1:8080/static; 后面static没有 “/”

   server {
        listen      80;
        server_name www.test.com;
        
        # 当访问 http://test.yeguxin.top/proxy/aaa/bbb.text时,nginx匹配到 /proxy/路径,把请求转发给127.0.0.1:8080服务.
        # 实际请求代理服务器路径为 " 127.0.0.1:8080/staticaaa/bbb.text "
        location /proxy/ {
             proxy_pass http://127.0.0.1:8080/static;
        }
    }

4.proxy_pass http://127.0.0.1:8080/static; 后面static有 “/”

 server {
        listen      80;
        server_name www.test.com;
        
        # 当访问 http://test.yeguxin.top/proxy/aaa/bbb.text时,nginx匹配到 /proxy/路径,把请求转发给127.0.0.1:8080服务.
        # 实际请求代理服务器路径为 " 127.0.0.1:8080/static/aaa/bbb.text "
        location /proxy/ {
             proxy_pass http://127.0.0.1:8080/static/;
        }
    }

5.最基本proxy_pass 用法

  server {
    listen      80;
    server_name chat.paas.scorpio.uat.newtank.cn;
    
     # 转发请求到 http://www.example.com
    location / {
        proxy_pass http://www.example.com;
    }
}

6.二级域名转发

 server {
    listen      5599;
    server_name localhost;

    location / {
        proxy_pass http://www.baidu.com;
    }
}    
 server {
    listen      5598;
    server_name localhost;
    
    location /jinpg/ {
        proxy_pass http://127.0.0.1:5599/;
    }
}