2019独角兽企业重金招聘Python工程师标准>>>
写在前面
很多时候第三方平台依赖公网,无法通过本地开发环境进行调试, 今天就记录一下互联网访问本地开发环境的方法.
配置服务器nginx
通过nginx的反向代理,代理到localhost:port ,看一下配置文件
server{
listen 443;
server_name 域名;
ssl on;
ssl_certificate cert/证书.pem;
ssl_certificate_key cert/证书.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
client_body_buffer_size 6m;
client_max_body_size 10m;
#proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:5000;
}
}
因为是api,这里采用https的方式配置了证书. 证书可以申请免费的.
通过ssh 转发
通过ssh 讲服务器的5000端口转发到本地的某个端口,也就是本地开发环境的端口.
ssh -vnNt -R 5000:localhost:5000 root@IP地址
debug1: Remote connections from LOCALHOST:5000 forwarded to local address localhost:5000
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: remote forward success for: listen 5000, connect localhost:5000
debug1: All remote forwarding requests processed
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 1 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 5000, originator 127.0.0.1 port 33370
debug1: connect_next: host localhost ([127.0.0.1]:5000) in progress, fd=4
debug1: channel 0: new [127.0.0.1]
debug1: confirm forwarded-tcpip
debug1: channel 0: connected to localhost port 5000
debug1: channel 0: free: 127.0.0.1, nchannels 1
通过公网访问就可以转发到本地开发环境了.