frp + nginx 实现 https 穿透

frp + nginx 实现 https 穿透

月光魔力鸭

2020-06-10 15:37 阅读 2645 喜欢 0 frp https nginx + frp

通过frp做穿透实现https 访问本地http项目。

项目需要https环境,由于开发状态中,需要做一个穿透,之前都是 frp 做的 http穿透,比较简单,结果找了下https的资料和github上的怎么都不行,瞎折腾了一个小时...

准备

证书申请,然后下载,拿到nginx配置的两个文件.

然后,确保本地项目能正常启动并可以访问,我本地的是: http://localhost:8090/example

下载对应的frp软件,我使用的是0.33 版本(最新的),地址https://github.com/fatedier/frp/releases ,下载对应的windows 和 linux版本。

nginx 配置

    # frp 穿透 https://live.example.com
    server {
        listen 443 ssl;
        server_name live.example.com;

        location / {
            proxy_pass   http://localhost:5556;
            client_max_body_size    1000m;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header User-Agent $http_user_agent;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
        ssl_certificate cert/1_live.example.com_bundle.crt;
        ssl_certificate_key cert/2_live.example.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
        ssl_prefer_server_ciphers on;
    }

frps.ini

[common]
bind_port = 7001
vhost_http_port = 5556
vhost_https_port = 5557

frpc.ini

[common]
server_addr = 59.222.12.198
server_port = 7001

[test_https]
type = http
local_port = 8090
custom_domains = live.example.com

启动

server端

./frps -c ./frps.ini

client端

./frpc -c ./frpc.ini

这里面碰到一个问题,jsp中的request.getServerPort() 得到的总是80 ,本应该是443 ,解决:

# 增加 $server_port 即可
proxy_set_header Host $host:$server_port;

第二个问题,request.getScheme() 得到的总是 http ,查资料说是:

# 增加这一句
proxy_set_header X-Forwarded-Proto $scheme;

不过对于我来说没有解决,框架是springboot ,目前直接写死了,先测试用着。

转载请注明出处: https://chrunlee.cn/article/frp-https-nginx.html


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
最近有一个任务一直在占满cpu, 总是会让我的服务器宕机,可是还得跑,想来想去想到了docker,印象中可以对cpu进行限制,这里简单记录下过程。
上一章,我们学习和了解了websocket 是什么以及初始搭建,接下来,我们继续了解,如何进行广播以及对应的私聊呢。
docker build 执行yum失败,找不到repo
mysql主从复制简单模式,一主一从。
最近有系统需要知道性能瓶颈,尝试使用jmeter对重要接口进行并发测试,确定能否支撑一定的用户数量。
前几天同事抱怨说微博太费劲了... 一万多条记录,可能会把他累死,我心想.. 重复工作不都可以用程序代替么..
昨天实现一个tabbar的时候发现怎么都无法跳转,直接拿的官方的demo,后来才发现是自定义tabbar的问题。
当我们使用web打印相关的解决方案的时候,还有不少小坑值得注意下,同时需要了解几个小技巧提升在web打印上的友好度,以下整理一些常见的小技巧