frp+nginx內網穿透
背景:自己有台內網Linux主機,希望被外網訪問(ssh、http、https);
准備工作
- 內網Linux主機-c,可以訪問c主機和外網的主機-s(windows/linux)
- 官網下載nginx到s:https://nginx.org/en/download.html
- github上下載windows版frp到s:https://github.com/fatedier/frp/releases
- github上下載linux版frp到c:https://github.com/fatedier/frp/releases
s端配置步驟
- 配置nginx:
#443端口https請求反向代理
server {
#監聽端口
listen 443 ssl;
server_name localhost;
#ssl自簽證書請參考我另一篇文章 https://www.cnblogs.com/zhoux123/p/14753126.html
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
#反向代理地址
proxy_pass http://localhost:8088;
}
}
- 配置
frps.ini
:
[common]
#日志輸出路徑:默認控制台
#log_file = ./frps.log
#日志輸出等級:trace, debug, info, warn, error(默認info)
#log_level = trace
#s端和c端建立連接綁定的端口,默認7000
bind_port = 7000
#此端口上的http請求將會轉發到c端
vhost_http_port = 8088
- 啟動nginx服務
- 啟動c端frps服務:
./frps -c ./frps.ini
,日志如下
2021/05/11 22:35:24 [I] [service.go:192] frps tcp listen on 0.0.0.0:7000
2021/05/11 22:35:24 [I] [service.go:235] http service listen on 0.0.0.0:8088
2021/05/11 22:35:24 [I] [root.go:209] frps started successfully
c端配置步驟
- 配置
frpc.ini
:
[common]
#日志輸出路徑:默認控制台
#log_file = ./frpc.log
#日志輸出等級:trace, debug, info, warn, error(默認info)
#log_level = trace
#s端地址
server_addr = 192.168.137.1
#s端和c端建立連接綁定的端口,默認7000
server_port = 7000
[ssh]
type = tcp
local_ip = 127.0.0.1
#默認22端口,termux為8022
local_port = 8022
remote_port = 6000
[http]
type = http
#s端的http請求將會轉發到此端口
local_port = 8080
#s端地址,可同時設置多個,英文逗號隔開
custom_domains = localhost,127.0.0.1,192.168.137.1
- 啟動c端frpc服務:
./frpc -c ./frpc.ini
,日志如下:
2021/05/11 22:41:43 [I] [service.go:304] [02c28f30442a89bd] login to server success, get run id [02c28f30442a89bd], server udp port [0]
2021/05/11 22:41:43 [I] [proxy_manager.go:144] [02c28f30442a89bd] proxy added: [ssh http]
2021/05/11 22:41:43 [I] [control.go:180] [02c28f30442a89bd] [http] start proxy success
2021/05/11 22:41:43 [I] [control.go:180] [02c28f30442a89bd] [ssh] start proxy success
驗證
找一台可以訪問s主機的電腦驗證:
- 驗證ssh:
ssh root@192.168.137.1 -p 7000
- 驗證http:
http://192.168.137.1:8088
- 驗證https:
https://192.168.137.1
或https://192.168.137.1:443
尊重原創,轉載請標明出處,謝謝