nginx 代理外网访问本地服务

nginx 代理外网访问本地服务

在做微信公众号开发的时候, 需要有一台外网服务器供微信接入。每次本地代码都需要提交到这台服务器上才能够调试。最近得空,使用nginx和ssh实现了本地服务器代理外网服务器。有两个步骤:

一、配置nginx

linux默认安装nginx,配置如下:

location / {

# First attempt to serve request as file, then

# as directory, then fall back to displaying a 404.

# try_files $uri $uri/ =404;

# Uncomment to enable naxsi on this location

# include /etc/nginx/naxsi.rules

proxy_pass

http://localhost:3000

;


}


二、开启ssh隧道

执行命令:


ssh -R [proxy_pass的端口号]:localhost:[本地服务端口号] root@[外网服务器地址] -N

发布于 2017-02-03 15:24