nps实现代理,实现http请求代理到内网http端口

nps实现代理,实现http请求代理到内网http端口

背景:

相关地址: nps github地址:

CentOS服务器端安装包:

Windows客户端安装包:

在CentOS服务器上安装nps server

直接解压linux_arm64_server.tar.gz

tar -zxvf linux_arm64_server.tar.gz

修改nps.conf

appname = nps
#Boot mode(dev|pro)
runmode = pro

#HTTP(S) proxy port, no startup if empty
http_proxy_ip=0.0.0.0
http_proxy_port=8088
#https_proxy_port=443
#https_just_proxy=true
#default https certificate setting
#https_default_cert_file=conf/server.pem
#https_default_key_file=conf/server.key

##bridge
bridge_type=tcp
bridge_port=8024
bridge_ip=0.0.0.0

启动nps server

./nps start

访问nps server管理界面

http://localhost:8080

现在有个需求访问http://api.example.com代理到内网http://127.0.0.1:8080端口

主要流程如下: http://api.example.com -> nps server -> http://127.0.0.1:8080

http://api.example 通过nginx代理到nps server的8088端口

配置如下: default.conf

server {
          
   
    listen       80;
    listen       443 ssl;
    server_name  api.example.com;

    include /etc/nginx/common/example.com.ssl.conf;

    location / {
          
   
        proxy_pass http://localhost:8088;
    }

   if ($scheme != https) {
          
   
        rewrite ^(.*)$  https://$server_name$1 permanent;
   }

}

example.com.ssl.conf

ssl_certificate   cert/example.com/fullchain.cer;
ssl_certificate_key  cert/example.com/example.com.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;

在nps server web管理后台创建客户端

在Windows上安装nps client

直接解压win_amd64_client.tar.gz 配置npc.conf

[common]
server_addr=[nps server服务器IP]:8024
conn_type=tcp
vkey=[客户端vkey]
auto_reconnection=true
max_conn=1000
flow_limit=1000
rate_limit=1000
basic_username=11
basic_password=3
web_username=user
web_password=1234
crypt=true
compress=true

启动客户端 nps -config=conf/npc.conf 启动成功后可以看到client list id为2的client状态变为online的状态

配置域名解析

配置成功后,访问http://api.example.com 会被代理到内网的http://localhost:8080端口

经验分享 程序员 微信小程序 职场和发展