一、配置服务器
1、在Centos上安装Nginx
yum install nginx
service nginx start
2、编辑nginx的配置文件
sudo nano /etc/nginx/conf.d/default.conf
server {
listen 10000;
server_name www.ccccccc.com;
location / {
proxy_pass http://127.0.0.1:20000;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
此配置是让Nginx监听10000端口,并把10000端口代理到本地的20000端口上。
二、 配置客户端
ssh root@www.ccccccc.com -R 20000:127.0.0.1:10000
将本机的10000端口映射到外网服务器的20000端口上。
所以代理的流程就是
www.ccccccc.com:10000 -> www.ccccccc.com:20000 -> localhost:10000
从而实现通过外网访问本地web环境,在做各种需要回调的接口时可以方便的在本地进行调试。