Menu Home

NPS 内网穿透代理服务器

内网穿透是指将内网中的软件服务通过网络代理方式暴露给广域网用户。
可以实现内网穿透的方式很多,比如通过防火墙硬件映射、网络穿透软件等等来进行实现。

典型使用场景

  1. 公司内部搭建了一个为知笔记的私有部署服务器,由于采用了拨号上网无固定IP地址,无法直接端口映射提供公网访问;
  2. 公司有一台公网虚拟服务器展示官方网站,但由于性能较弱无法搭建更多的复杂业务;
  3. 通过 NPS内网穿透代理服务器 可以实现将公网服务器的端口映射到内网,提供公网访问内网资源的能力。同时无需对公司防火墙进行任何映射操作。保证公司内网的安全。

NPS 一款轻量级、高性能、功能强大的内网穿透代理服务器

  • 协议支持全面,兼容几乎所有常用协议,例如tcp、udp、http(s)、socks5、p2p、http代理…
  • 全平台兼容(linux、windows、macos、群辉等),支持一键安装为系统服务
  • 控制全面,同时支持服务端和客户端控制
  • https集成,支持将后端代理和web服务转成https,同时支持多证书
  • 操作简单,只需简单的配置即可在web ui上完成其余操作
  • 展示信息全面,流量、系统信息、即时带宽、客户端版本等
  • 扩展功能强大,该有的都有了(缓存、压缩、加密、流量限制、带宽限制、端口复用等等)
  • 域名解析具备自定义header、404页面配置、host修改、站点保护、URL路由、泛解析等功能
  • 服务端支持多用户和用户注册功能

服务端服务器(公网服务器)通过DOCKER方式安装配置

服务器端需要安装到公网服务器上,本案例公网环境如下:
阿里云轻量服务器 Ubuntu Server 20.04 Lts

magth@storage:~$ sudo docker pull ffdfgdfg/nps
magth@storage:~$ mkdir nps/conf
magth@storage:~$ cd nps/conf
magth@storage:~/nps/conf$ vim nps.conf
...
appname = nps 
#Boot mode(dev|pro)
runmode = dev

#HTTP(S) proxy port, no startup if empty
http_proxy_ip=0.0.0.0
http_proxy_port=8011   
https_proxy_port=
https_just_proxy=false
#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

# Public password, which clients can use to connect to the server
# After the connection, the server will be able to open relevant ports and parse related domain names according to its own configuration file.
public_vkey=123

#Traffic data persistence interval(minute)
#Ignorance means no persistence
#flow_store_interval=1

# log level LevelEmergency->0  LevelAlert->1 LevelCritical->2 LevelError->3 LevelWarning->4 LevelNotice->5 LevelInformational->6 LevelDebug->7
log_level=7
#log_path=nps.log

#Whether to restrict IP access, true or false or ignore
#ip_limit=true

#p2p
p2p_ip=127.0.0.1
p2p_port=6000

#web 服务器WEB管理界面配置
web_host=yourdomain.com          # web 访问域名
web_username=admin               # web 访问用户
web_password=123                 # web 访问密码
web_port=8124                    # web 访问端口,服务器防火墙需打开此端口
web_ip=0.0.0.0
web_base_url=
web_open_ssl=true                # web 管理启用SSL
web_cert_file=conf/ca/nps.crt    # SSL 证书
web_key_file=conf/ca/nps.key     # SSL KEY
# if web under proxy use sub path. like http://host/nps need this.
#web_base_url=/nps

#Web API unauthenticated IP address(the len of auth_crypt_key must be 16)
#Remove comments if needed
#auth_key=test
auth_crypt_key =1234567812345678

#allow_ports=9001-9009,10001,11000-12000

#Web management multi-user login
allow_user_login=false
allow_user_register=false
allow_user_change_username=false


#extension
allow_flow_limit=false
allow_rate_limit=false
allow_tunnel_num_limit=false
allow_local_proxy=false
allow_connection_num_limit=false
allow_multi_ip=false
system_info_display=false

#cache
http_cache=false
http_cache_length=100

#get origin ip
http_add_origin_header=false

#pprof debug options
#pprof_ip=0.0.0.0
#pprof_port=9999

#client disconnect timeout
disconnect_timeout=60
...
magth@storage:~/nps/conf$ sudo docker run -d \
--name nps --net=host \  
-v ~/nps/conf:/conf \   # 配置文件映射到DOCKER内
ffdfgdfg/nps

至此服务器端安装完毕,后续服务器端配置可使用WEB管理界面进行。
根据以上的配置文件,WEB管理界面访问地址  https://yourdomain.com:8124

新建客户端 只需填写备注信息即可,其他均可为空

客户端服务器(内网服务器)安装配置

客户端服务器需要安装到部署具体业务的内网服务器,本案例内网环境如下:
Dell Edge R230 服务器 Ubuntu Server 20.04 Lts

magth@storage:~$ mkdir npc
magth@storage:~$ cd npc
magth@storage:~/npc$ wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz
magth@storage:~/npc$ tar -zxvf linux_amd64_client.tar.gz
# 注册客户端命令为服务,具体命令见上图客户端命令
magth@storage:~/npc$ sudo ./npc -server=youdomain.com:8024 -vkey=xxxxxxxxx -type=tcp 
magth@storage:~/npc$ sudo npc start # 启动客户端
magth@storage:~/npc$ sudo npc stop  # 停止客户端

客户端启动后上图刚刚新建的客户端将显示状态开放,连接在线

至此NPS内网穿透服务器、客户端基本的安装配置连接完毕。在下一节内容种我们将前一节在内网搭建的 为知笔记 私有部署 通过 NPS 映射到公网访问。

Categories: 工具技巧

Tagged as:

RoyAkon