经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Linux/Shell » 查看文章
frp+nginx内网穿透
来源:cnblogs  作者:zhoux123  时间:2021/5/24 10:45:54  对本文有异议

frp+nginx内网穿透

背景:自己有台内网Linux主机,希望被外网访问(ssh、http、https);

准备工作

  1. 内网Linux主机-c,可以访问c主机和外网的主机-s(windows/linux)
  2. 官网下载nginx到s:https://nginx.org/en/download.html
  3. github上下载windows版frp到s:https://github.com/fatedier/frp/releases
  4. github上下载linux版frp到c:https://github.com/fatedier/frp/releases

s端配置步骤

  1. 配置nginx:
  1. #443端口https请求反向代理
  2. server {
  3. #监听端口
  4. listen 443 ssl;
  5. server_name localhost;
  6. #ssl自签证书请参考我另一篇文章 https://www.cnblogs.com/zhoux123/p/14753126.html
  7. ssl_certificate server.crt;
  8. ssl_certificate_key server.key;
  9. ssl_session_cache shared:SSL:1m;
  10. ssl_session_timeout 5m;
  11. ssl_ciphers HIGH:!aNULL:!MD5;
  12. ssl_prefer_server_ciphers on;
  13. location / {
  14. #反向代理地址
  15. proxy_pass http://localhost:8088;
  16. }
  17. }
  1. 配置frps.ini
  1. [common]
  2. #日志输出路径:默认控制台
  3. #log_file = ./frps.log
  4. #日志输出等级:trace, debug, info, warn, error(默认info)
  5. #log_level = trace
  6. #s端和c端建立连接绑定的端口,默认7000
  7. bind_port = 7000
  8. #此端口上的http请求将会转发到c端
  9. vhost_http_port = 8088
  1. 启动nginx服务
  2. 启动c端frps服务:./frps -c ./frps.ini,日志如下
  1. 2021/05/11 22:35:24 [I] [service.go:192] frps tcp listen on 0.0.0.0:7000
  2. 2021/05/11 22:35:24 [I] [service.go:235] http service listen on 0.0.0.0:8088
  3. 2021/05/11 22:35:24 [I] [root.go:209] frps started successfully

c端配置步骤

  1. 配置frpc.ini
  1. [common]
  2. #日志输出路径:默认控制台
  3. #log_file = ./frpc.log
  4. #日志输出等级:trace, debug, info, warn, error(默认info)
  5. #log_level = trace
  6. #s端地址
  7. server_addr = 192.168.137.1
  8. #s端和c端建立连接绑定的端口,默认7000
  9. server_port = 7000
  10. [ssh]
  11. type = tcp
  12. local_ip = 127.0.0.1
  13. #默认22端口,termux为8022
  14. local_port = 8022
  15. remote_port = 6000
  16. [http]
  17. type = http
  18. #s端的http请求将会转发到此端口
  19. local_port = 8080
  20. #s端地址,可同时设置多个,英文逗号隔开
  21. custom_domains = localhost,127.0.0.1,192.168.137.1
  1. 启动c端frpc服务:./frpc -c ./frpc.ini,日志如下:
  1. 2021/05/11 22:41:43 [I] [service.go:304] [02c28f30442a89bd] login to server success, get run id [02c28f30442a89bd], server udp port [0]
  2. 2021/05/11 22:41:43 [I] [proxy_manager.go:144] [02c28f30442a89bd] proxy added: [ssh http]
  3. 2021/05/11 22:41:43 [I] [control.go:180] [02c28f30442a89bd] [http] start proxy success
  4. 2021/05/11 22:41:43 [I] [control.go:180] [02c28f30442a89bd] [ssh] start proxy success

验证

找一台可以访问s主机的电脑验证:

  1. 验证ssh:ssh root@192.168.137.1 -p 7000
  2. 验证http:http://192.168.137.1:8088
  3. 验证https:https://192.168.137.1https://192.168.137.1:443

尊重原创,转载请标明出处,谢谢

原文链接:http://www.cnblogs.com/zhoux123/p/14758051.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号