实时本地调试线上页面

使用ngnix来作普通的正向代理。配置如下:
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
server {
    listen       8000; #监听端口,这里监听8000
    #server_name  localhost;
    resolver 8.8.8.8; #域名解析服务器
    location / {
        #这里指定本机代码仓库的静态文件目录,这里不设置就是直接取线下服务器的文件
        root   /Users/xp/projects/meituan.www/static;
        #取消默认文档
        #index  index.html index.htm;
        #如果访问的是文件夹,就是找默认文档,代理到原地址去找
        if ($request_uri ~* \/$ ){
            proxy_pass http://$http_host;
        }
        #如果目标url对应的文件没找到,就代理到原地址去找
        if (!-e $request_filename) {
            proxy_pass http://$http_host;
        }
        #如果对应的host是CDN服务器,就代理到线下的CDN测试服务器,以下的s1是一个意思
        if ($http_host = s0.meituan.net){
            proxy_pass http://s0.xpmt.meituan.com;
        }
        if ($http_host = s1.meituan.net){
            proxy_pass http://s1.xpmt.meituan.com;
        }
        #如果对应的host是Combo服务器,就代理到线下的Combo服务器
        if ($http_host = c.meituan.net){
            proxy_pass http://c.xpmt.meituan.com;
        }
    }
}

浏览器如Firefox/Chrome/IE等设置代理服务器为localhost,端口为8000即可。

线下服务器使用的是Git仓库中的代码,实时调试线上页面,如果测试OK了,即可push到远程仓库立即部署上线。

原文地址:https://www.cnblogs.com/shihao/p/2318296.html