Nginx操作:显示代理IP与配置多个静态文件

    今天使用Nginx ,排查一个问题,负载过程,登陆应用提示“暂无权限”! 需要查看负载真实IP信息就有了这篇记录。

    先上脚本:

#add_header backendIP $upstream_addr;   #展示真实IP
#add_header backendCode $upstream_status;    #展示负载请求状态码
    #对IP a+b 做负载
    upstream  test{
          server xxxxxxxA;
          server xxxxxxxB;
    }

    location / {
      add_header backendIP $upstream_addr;      
      proxy_pass    http://test;
      proxy_connect_timeout   900;  
            proxy_send_timeout      900;  
            proxy_read_timeout      900; 
            send_timeout  900;
     }

    因为要在负载下调试程序,但是程序断点没有生效,nginx 默认不会展示具体的负载地址;要看到具体是请求到哪台服务器,就需要修改nginx  的*.conf 配置,以便获取请求地址信息。加完上述脚本后,状态如下图所示:

    nginx  配置多个静态文件

  

server
{
    listen 80;    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }    
    location / {
        index beijing.html;
    }
    #配置替代名称 alias
    location /shenzhen {
        alias /www/wwwroot/lowcarbon.pins.cn/shenzhen; #相当于 [alias]+/shenzhen/source.*
        index shenzhen.html;
    }
    location /beijing {
        alias /www/wwwroot/lowcarbon.pins.cn/beijing;
        index beijing.html;
    }
}
## window 下
#启动
start nginx.exe
#停止 stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息
nginx.exe -s stop
nginx.exe -s quit
#重新载入
nginx.exe -s reload
#根据名称查询 window 下的nginx 的启动进程
tasklist /fi “imagename eq nginx.exe”
#删除这个命令进程后就没法执行 nignx 命令
taskkill /f /pid 13568
#删除2312进程后 nginx 就停止了
netstat -ano | findstr 30090

 

 引用:https://blog.csdn.net/CNAHYZ/article/details/103224687       https://blog.csdn.net/tryyourbest0928/article/details/115655352

 

posted @ 2022-11-07 10:29  天為  阅读(802)  评论(0编辑  收藏  举报