重置了服务器之后,需要重新配置nps,nginx等用作反向代理。这次为了简化服务器的功能,就不再使用源码安装了,走一遍整个流程,记录一下方便下次部署服务器。采用源码部署的方式可以参考我之前的文章,宝塔面板部署nps

1. nps的介绍

项目Github主页:nps

nps是一款轻量级、高性能、功能强大的内网穿透代理服务器。目前支持tcp、udp流量转发,可支持任何tcp、udp上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还支持内网http代理、内网socks5代理、p2p等,并带有功能强大的web管理端。

简单来说,当我们家里的设备没有公网ip时,我们可以利用一台有公网ip的服务器,用作流量转发。让没有公网ip始终和公网服务器连接,当我们想访问这台设备的时候,只需要访问公网服务器的某个端口就可以访问到内网设备。 后台界面

2. Docker 部署nps

作者nps/npc文档

  • 首先需要下载配置文件conf,可以到项目release中下载,也可以直接从这里下载

解压之后我们打开nps.conf这个文件,如下:

appname = nps
#Boot mode(dev|pro)
runmode = dev
#11
#HTTP(S) proxy port, no startup if empty
http_proxy_ip=0.0.0.0
http_proxy_port=80    # 注意这里,如果安装了nginx等程序需要注意端口占用,如果不懂可以直接删了##11 这部分内容
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
##11

##bridge
bridge_type=tcp
bridge_port=8024 # 这里是服务端和客户端连接的端口,需要在防火墙放行
bridge_ip=0.0.0.0 # 表示允许所有ip访问

# 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_host=a.o.com # 这里改为服务器公网ip或者对应的域名
web_username=admin # 面板的用户名
web_password=123 # 面板密码
web_port = 8080 # 面板的端口号
web_ip=0.0.0.0
web_base_url=
web_open_ssl=false  # 如果需要https访问,改为true,然后证书密钥路径在下两行修改好 记得挂载在容器上
web_cert_file=conf/server.pem
web_key_file=conf/server.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

  • 运行nps

直接使用下面的代码,运行nps。

docker run -d --name nps --net=host -v <本机conf目录>:/conf ffdfgdfg/nps

例如我把上面的conf文件夹存放到/root/conf这里,那么就是docker run -d --name nps --net=host -v /root/conf:/conf ffdfgdfg/nps 那么就可以使用ip+8080端口访问后台了。

  • 新建客户端 点击新建 验证密钥会自动生成,新建客户端后点击编辑或者左边的➕可以查看到密钥。这个后面npc客户端连接会用到。
  • 新建连接

选择TCP隧道,并新建。

3. Docker 部署npc

上面介绍的是服务端,下面介绍一下客户端如何安装。

docker run -d --name npc --net=host ffdfgdfg/npc -server=ip地址:8024 -vkey=验证密钥 -type=tcp

验证密钥就是在管理端查看的。 运行后就可以在后台看到客户端已经在线了。如何内网穿透远程桌面