[GH-ISSUE #1351] [建议]HTTP重定向到HTTPS #1069

Closed
opened 2026-05-05 12:41:14 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @withsalt on GitHub (Aug 2, 2019).
Original GitHub issue: https://github.com/fatedier/frp/issues/1351

What version of frp are you using (./frpc -v or ./frps -v)?
0.28.0

What operating system and processor architecture are you using (go env)?
Debain 9

建议增加一个http重定向到https的功能。
场景:
1、在后端api部署的过程中,有事不允许http访问的,可以将http直接永久重定向到https
2、在实现从定向的过程中,很多时候是Nginx配合frps使用。frps可以重定向http的话,就不用再安装nginx了。

Originally created by @withsalt on GitHub (Aug 2, 2019). Original GitHub issue: https://github.com/fatedier/frp/issues/1351 **What version of frp are you using (./frpc -v or ./frps -v)?** 0.28.0 **What operating system and processor architecture are you using (`go env`)?** Debain 9 建议增加一个http重定向到https的功能。 场景: 1、在后端api部署的过程中,有事不允许http访问的,可以将http直接永久重定向到https 2、在实现从定向的过程中,很多时候是Nginx配合frps使用。frps可以重定向http的话,就不用再安装nginx了。
Author
Owner

@status301 commented on GitHub (Aug 3, 2019):

不建议frp添加重定向功能,但是建议在 http转https中添加head,我中午会将代码贴出,完全可以用head,在本地服务代码中控制是否使用https

<!-- gh-comment-id:517889687 --> @status301 commented on GitHub (Aug 3, 2019): 不建议frp添加重定向功能,但是建议在 http转https中添加head,我中午会将代码贴出,完全可以用head,在本地服务代码中控制是否使用https
Author
Owner

@status301 commented on GitHub (Aug 3, 2019):

我是启在docker中的,脱敏了一下
frps

[root@HK ~]# cat frps.ini
[common]
token = ******
#bind_addr = 0.0.0.0
bind_port = 80
bind_udp_port = 81
kcp_bind_port = 80
vhost_http_port = 80
vhost_https_port = 443
vhost_http_timeout = 60
#subdomain_host = ****.**

#dashboard_addr = 0.0.0.0
dashboard_port = 65534
dashboard_user = ***
dashboard_pwd = ***
heartbeat_timeout = 60

#log_file = /var/log/frps.log
# trace, debug, info, warn, error
log_level = trace
#log_max_days = 1

#allow_ports = 2000-3000,3001,3003,4000-50000
#max_pool_count = 5
max_ports_per_client = 0
tcp_mux = true

frpc

[root@HK ~]# cat frpc.ini
[common]
token = ***
server_port = 80
server_addr = ***
protocol = tcp
admin_user = ???
admin_pwd = ???
admin_port = 65535
user = X

#log_max_days = 1
log_level = trace
#trace,debug,info,warn,error
#log_file = /var/log/frpc.log

[CloudController]
type = http
local_port = 65535
custom_domains = 0d9e8a65-b88b-4f68-53f5-23a422f5d1de.aaaaadomain.cn

[S*]
type = https
custom_domains = *.aaaaadomain.cn
header_security = https
plugin = https2http
plugin_local_addr = 172.17.0.1:80
plugin_crt_path = /root/cert/aaaaadomain.cn/fullchain.cer
plugin_key_path = /root/cert/aaaaadomain.cn/aaaaadomain.cn.key
header_X-From-Where = s

########## tcp ##########
[MySql]
type = tcp
local_ip = bdm28xxxxx9.com
local_port = 3306
remote_port = 33306
health_check_type = tcp
health_check_timeout_s = 3
health_check_max_failed = 30
health_check_interval_s = 30

########################################
[H@]
type = http
local_port = 80
local_ip = aaaaadomaincn.github.io
host_header_rewrite = aaaaadomain.cn
custom_domains = aaaaadomain.cn

[api]
type = http
local_ip = 172.17.0.1
local_port = 65534
custom_domains = api.aaaaadomain.cn
header_custom_domains = api

[fy]
type = http
local_port = 80
local_ip = vpsdomain.xyz
host_header_rewrite = vpsdomain.xyz
custom_domains = fy.aaaaadomain.cn
header_X-From-Where = fy

[HKM]
type = http
local_port = 80
local_ip = vpsdomain.xyz
host_header_rewrite = vpsdomain.xyz
custom_domains = dashboard.aaaaadomain.cn
header_X-From-Where = frp

[QR]
type = http
local_port = 80
local_ip = vpsdomain.xyz
host_header_rewrite = vpsdomain.xyz
custom_domains = qr.aaaaadomain.cn
header_X-From-Where = qr
[root@HK ~]#
[root@HK tmp]#

<!-- gh-comment-id:517890457 --> @status301 commented on GitHub (Aug 3, 2019): 我是启在docker中的,脱敏了一下 frps ``` [root@HK ~]# cat frps.ini [common] token = ****** #bind_addr = 0.0.0.0 bind_port = 80 bind_udp_port = 81 kcp_bind_port = 80 vhost_http_port = 80 vhost_https_port = 443 vhost_http_timeout = 60 #subdomain_host = ****.** #dashboard_addr = 0.0.0.0 dashboard_port = 65534 dashboard_user = *** dashboard_pwd = *** heartbeat_timeout = 60 #log_file = /var/log/frps.log # trace, debug, info, warn, error log_level = trace #log_max_days = 1 #allow_ports = 2000-3000,3001,3003,4000-50000 #max_pool_count = 5 max_ports_per_client = 0 tcp_mux = true ``` frpc ``` [root@HK ~]# cat frpc.ini [common] token = *** server_port = 80 server_addr = *** protocol = tcp admin_user = ??? admin_pwd = ??? admin_port = 65535 user = X #log_max_days = 1 log_level = trace #trace,debug,info,warn,error #log_file = /var/log/frpc.log [CloudController] type = http local_port = 65535 custom_domains = 0d9e8a65-b88b-4f68-53f5-23a422f5d1de.aaaaadomain.cn [S*] type = https custom_domains = *.aaaaadomain.cn header_security = https plugin = https2http plugin_local_addr = 172.17.0.1:80 plugin_crt_path = /root/cert/aaaaadomain.cn/fullchain.cer plugin_key_path = /root/cert/aaaaadomain.cn/aaaaadomain.cn.key header_X-From-Where = s ########## tcp ########## [MySql] type = tcp local_ip = bdm28xxxxx9.com local_port = 3306 remote_port = 33306 health_check_type = tcp health_check_timeout_s = 3 health_check_max_failed = 30 health_check_interval_s = 30 ######################################## [H@] type = http local_port = 80 local_ip = aaaaadomaincn.github.io host_header_rewrite = aaaaadomain.cn custom_domains = aaaaadomain.cn [api] type = http local_ip = 172.17.0.1 local_port = 65534 custom_domains = api.aaaaadomain.cn header_custom_domains = api [fy] type = http local_port = 80 local_ip = vpsdomain.xyz host_header_rewrite = vpsdomain.xyz custom_domains = fy.aaaaadomain.cn header_X-From-Where = fy [HKM] type = http local_port = 80 local_ip = vpsdomain.xyz host_header_rewrite = vpsdomain.xyz custom_domains = dashboard.aaaaadomain.cn header_X-From-Where = frp [QR] type = http local_port = 80 local_ip = vpsdomain.xyz host_header_rewrite = vpsdomain.xyz custom_domains = qr.aaaaadomain.cn header_X-From-Where = qr [root@HK ~]# [root@HK tmp]# ```
Author
Owner

@status301 commented on GitHub (Aug 3, 2019):

因为http2https是号匹配的,所以所有.aaaaadomain.cn的三级域名都可以使用https!
不过因为http2https不能加head,所以在html中加了下面的js,让页面跳到https去

function js(){
    if($_SERVER["HTTP_X_FROM_WHERE"]!="bbbdomain.win")
		echo "
	window.onload = function(){
		if('https:' != document.location.protocol){
			var urls=window.location.href;
			urls = urls.replace('http', 'https');
			window.location=urls;
		}
	}";

<!-- gh-comment-id:517890776 --> @status301 commented on GitHub (Aug 3, 2019): 因为http2https是*号匹配的,所以所有*.aaaaadomain.cn的三级域名都可以使用https! 不过因为http2https不能加head,所以在html中加了下面的js,让页面跳到https去 ``` function js(){ if($_SERVER["HTTP_X_FROM_WHERE"]!="bbbdomain.win") echo " window.onload = function(){ if('https:' != document.location.protocol){ var urls=window.location.href; urls = urls.replace('http', 'https'); window.location=urls; } }"; ```
Author
Owner

@status301 commented on GitHub (Aug 3, 2019):

已知bug,在配置*.xxx.cn的http2https后不能再单独配置某一个的https跳转,否则会内存移除,内存一直上涨

<!-- gh-comment-id:517890933 --> @status301 commented on GitHub (Aug 3, 2019): 已知bug,在配置*.xxx.cn的http2https后不能再单独配置某一个的https跳转,否则会内存移除,内存一直上涨
Author
Owner

@fatedier commented on GitHub (Aug 3, 2019):

@status301 能把你发现的 bug 单独提一个 issue 描述下吗?

<!-- gh-comment-id:517905753 --> @fatedier commented on GitHub (Aug 3, 2019): @status301 能把你发现的 bug 单独提一个 issue 描述下吗?
Author
Owner

@fatedier commented on GitHub (Aug 3, 2019):

@withsalt 建议配合 nginx 使用,frp 不会逐个实现 nginx 能够提供的基础能力。

<!-- gh-comment-id:517905912 --> @fatedier commented on GitHub (Aug 3, 2019): @withsalt 建议配合 nginx 使用,frp 不会逐个实现 nginx 能够提供的基础能力。
Author
Owner

@status301 commented on GitHub (Aug 3, 2019):

@fatedier 希望http2https中添加一个head,当前配置泛解析后,后台无法判断gui是http还是https访问的

<!-- gh-comment-id:517913693 --> @status301 commented on GitHub (Aug 3, 2019): @fatedier 希望http2https中添加一个head,当前配置泛解析后,后台无法判断gui是http还是https访问的
Author
Owner

@withsalt commented on GitHub (Aug 7, 2019):

@fatedier 好的,感谢。

<!-- gh-comment-id:519009534 --> @withsalt commented on GitHub (Aug 7, 2019): @fatedier 好的,感谢。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#1069
No description provided.