FRP内网穿透-HTTPS代理Web服务

通过自定义域名访问内网的 Web 服务

本文将介绍使用 自定义域名 通过FRP将内网机器上的web服务映射到外网,并且配置SSL证书,使用 HTTPS协议 访问。

需要使用的工具:

  • 域名一个(解析到 FRP服务端 机器上)
  • 域名证书(若不需要 https 可不需要)
  • NGINX(安装在 FRP客户端 机器上)

1. 配置FRP服务端

  • 配置 frps.toml
    在 frps.toml 文件中添加以下内容,以指定 HTTP 请求的监听端口为 80,HTTPS请求的监听端口为 443:

    toml 复制代码
    # HTTP 类型代理
    vhostHTTPPort = 80
    # HTTPS 类型代理
    vhostHTTPSPort = 443
  • 配置好需重启frps服务

    shell 复制代码
    sudo systemctl restart frps

2. 配置FRP客户端

  • 配置 frpc.toml
    在 frpc.toml 文件中添加一下内容,以指定访问域名及访问协议:

    toml 复制代码
    [[proxies]]
    name = "web1"
    type = "http"
    localPort = 80
    customDomains = ["test1.example.com"]
    
    [[proxies]]
    name = "web2"
    type = "https"
    localPort = 443
    customDomains = ["test2.example.com"]
  • 配置好需重启frpc服务

    shell 复制代码
    sudo systemctl restart frpc

3. 配置 NGINX

在内网机器上安装好Nginx
将SSL证书上传到内网机器

新增 nginx 配置(HTTP配置):

conf 复制代码
server {
	#HTTP 默认访问端口号为 80
	listen 80; 
	#请填写绑定证书的域名
	server_name test1.example.com; 

	location / {
		root   /opt/test/web1;
		try_files $uri $uri/ /index.html;
		index  index.html index.htm;
	}
}

新增 nginx 配置(HTTPS配置):

conf 复制代码
server {
	#HTTPS默认访问端口号为 443
	listen 443 ssl; 
	#请填写绑定证书的域名
	server_name test2.example.com; 
	#请填写证书文件的相对路径或绝对路径
	ssl_certificate /etc/nginx/conf.d/cert/test2.example.com.crt; 
	#请填写私钥文件的相对路径或绝对路径
	ssl_certificate_key /etc/nginx/conf.d/cert/test2.example.com.key; 
	ssl_session_timeout 5m;
	#请按照以下协议配置
	ssl_protocols TLSv1.2 TLSv1.3; 
	#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 
	ssl_prefer_server_ciphers on;

	location / {
		root   /opt/test/web2;
		try_files $uri $uri/ /index.html;
		index  index.html index.htm;
	}
}

配置好需 重载nginx配置

shell 复制代码
# 校验nginx配置
sudo nginx -t
# 重载nginx配置
sudo nginx -s reload

4. 访问web服务

分别访问 http://test1.example.com 、https://test2.example.com,能访问则说明配置成功。

上一章:FRP内网穿透-客户端(frpc)

相关推荐
码间留白7 小时前
手把手把 GitHub 推上阿里云 ECS:Actions CI/CD 全链路避坑实录(折腾好几天,到 2 分钟见绿)
运维·阿里云·ci/cd·docker·devops·github actions
吹什么轩8 小时前
linux系统复习:僵尸进程与孤儿进程
linux·运维·php
张宇Joaquin8 小时前
AMD uProf 工具采集微架构特征使用介绍
服务器
老李IT笔记9 小时前
连不上不一定是网不好:新系统不认的服务端配置卡在哪一档
运维·服务器·网络
小此方9 小时前
Linux网络(二十八):从NAT转换到正反向代理:图解内网通信、NAPT端口映射
linux·运维·网络
刚入门的大一新生9 小时前
Linux-进程池
linux·运维·服务器
万年咸鱼9 小时前
HTTPS 是如何保证传输安全的?
网络协议·安全·https
数据库小学妹9 小时前
数据库运维五级成熟度:监控、备份、高可用怎么串起来
运维·数据库·监控
AliCloudROS10 小时前
从 1 万到 20 万:OOS Loop 任务规模提升 20 倍的攻坚记录
运维·性能优化
鱼很腾apoc10 小时前
【MySQL】第4期 用户管理与 C 语言连接编程详解
linux·服务器·c语言·mysql·connector/c