java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

frp内网穿透 公网访问本地web服务http和https

  1. frp 消耗服务器流量测试 (2019 年 9 月 2 日)
  2. frp 对客户端简单的文件访问 (2019 年 8 月 24 日)
  3. frp 多台客户端通过一台服务器连接穿透 (2019 年 8 月 23 日)
  4. frp点对点udp方式内网穿透ssh,不走服务器流量 (2019 年 5 月 30 日)
  5. frp ssh 安全连接和服务器安全设置 (2019 年 5 月 29 日)
  6. frp 控制台监控dashboard配置 (2019 年 5 月 27 日)
  7. frp内网穿透 公网访问本地web服务http和https (2019 年 5 月 26 日)
  8. frp安装教程 穿透SSH (2019 年 5 月 25 日)
  9. frp内网穿透教程 (2019 年 5 月 25 日)

frp内网穿透的一个重要的作用就是在互联网上可以任意机器访问本地电脑的web服务

下面举例子用我的测试域名test.java-er.com 进行穿透

服务器上frps.ini文件增加vhost_http_port=82

[common]
bind_port = 7000
vhost_http_port = 82 #端口自己喜好来定

客户端机器 frpc.ini文件增加节点[web]

[common]
server_addr = 47.95.XX.XX #服务器IP 
server_port = 7000

[web]
type = http
local_port = 80 #本地http服务端口
custom_domains = test.java-er.com #服务器的域名

本地客户端机器apache配置文件端口为80,但是域名为test.java-er.com


    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Users/ge/ge/web/php/ge/javaer/h5"
    ServerName test.java-er.com
   # ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common



Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

最终访问的地址不是80,是通过了服务器的test.java-er.com:82穿透到本地http的80端口,所以外网访问地址为test.java-er.com:82

我在本地放一个文件index.php

';
echo '我是月小升本地机器的php文件index.php, 访问我的地址test.java-er.com:82';
?>

访问效果展示

2019-7-21更新
https配置

# frpc.ini
[common]
server_addr = x.x.x.x
server_port = 7000

[test_htts2http]
type = https
custom_domains = test.yourdomain.com

plugin = https2http
plugin_local_addr = 127.0.0.1:80

# HTTPS 证书相关的配置
plugin_crt_path = ./server.crt
plugin_key_path = ./server.key
plugin_host_header_rewrite = 127.0.0.1

1.本地的服务依然是http
2.https的key和crt 存在本地,配置给frp,不用在apache里配置,apache配置依然是http的。frp会帮助我们转化http为https

2019-08-15 内网机器断电重启动,https服务失效,查了半天
plugin_crt_path = ./server.crt
plugin_key_path = ./server.key

找不到ssl认证文件了。 所以以后配置路径开始就写全路径 /home/ssl/server.crt 就好了。


This entry was posted in Linux, MAC, PHP, 科技精品 and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/frp-web-network/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

4 Responses to frp内网穿透 公网访问本地web服务http和https

  1. XXX says:

    请问域名的DNS是不是需要设置什么?
    小白求指点…

  2. 月小升 says:

    域名解析到中转服务器上

  3. little says:

    为啥我会出现《无法访问此网站 xxxxx拒绝了我们的连接请求。》,然后如果我在frpc里面加#host_header_rewrite=xxxx,确实能访问,但是页面缺失,而且地址还是内网的192.168.x.xxx

Leave a Reply to XXX Cancel reply