互聯網訪問本地開發環境

寫在前面

不少時候第三方平臺依賴公網,沒法經過本地開發環境進行調試, 今天就記錄一下互聯網訪問本地開發環境的方法.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

相關文章
相關標籤/搜索