Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【bigo】nginx反向代理实现线上调试 #3

Open
yeyeye0525 opened this issue Nov 5, 2020 · 0 comments
Open

【bigo】nginx反向代理实现线上调试 #3

yeyeye0525 opened this issue Nov 5, 2020 · 0 comments

Comments

@yeyeye0525
Copy link
Contributor

yeyeye0525 commented Nov 5, 2020

前言

有时项目上线后,出现线上问题,依赖线上数据,但不方便调试定位问题。
线上资源反向代理,有两种方式:
一是通过fiddle、charles进行本地资源代理,参考:https://blog.csdn.net/weixin_39966065/article/details/99331857
二是通过nginx进行域名反向代理。
本文介绍nginx反向代理

1.流程图说明

1

  • 本地启动开发模式
  • 配置nginx,使生产域名代理到本地端口
  • 配置host,使生产域名解析到本地80端口
  • 浏览器访问生产域名,静态资源成功代理到本地项目,同时使用生产数据进行问题定位

2.操作实例

http://abc.bigo.sg 进行反向代理。

nginx配置如下:

server {
    listen      80;
    server_name  abc.bigo.sg;
    access_log /tmp/access.log main;
    error_log /tmp/error.log error;
 
    location ^~ /api/ { # 数据接口不代理
        proxy_pass         http://123.456.78:80; # ping abc.bigo.sg 获取到的实际ip地址
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host abc.bigo.sg;
    }
 
    location / {
        proxy_pass         http://127.0.0.1:3020;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    }
     
}

检验配置:nginx -t

重启服务:nginx -s reload

添加host
127.0.0.1 abc.bigo.sg

新开隐身窗口访问站点(避免dns缓存)
http://abc.bigo.sg

代理成功

@yeyeye0525 yeyeye0525 changed the title nginx反向代理实现线上调试 【bigo】nginx反向代理实现线上调试 Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant