互联网访问本地开发环境

写在前面

不少时候第三方平台依赖公网,没法经过本地开发环境进行调试, 今天就记录一下互联网访问本地开发环境的方法.nginx

配置服务器nginx

经过nginx的反向代理,代理到localhost:port ,看一下配置文件api

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端口转发到本地的某个端口,也就是本地开发环境的端口.session

ssh -vnNt -R 5000:localhost:5000 root@IP地址  
debug1: Remote connections from LOCALHOST:5000 forwarded to local address localhost:5000
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com 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

经过公网访问就能够转发到本地开发环境了.ssh

相关文章
相关标签/搜索