frp + nginx 实现 https 穿透

frp + nginx 实现 https 穿透

月光魔力鸭

2020-06-10 15:37 阅读 2594 喜欢 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


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
简单记录下dockerfile 以及compose配置
昨天客户发现了个小BUG,文章发布使用的ueditor, 上传视频的时候当时好好的,后来怎么就是播放不了?
近期有添加数学公式的需求,找来找去,最后还是选择了最简单的。tinymce+kityformula
当我们使用web打印相关的解决方案的时候,还有不少小坑值得注意下,同时需要了解几个小技巧提升在web打印上的友好度,以下整理一些常见的小技巧
通过registry 自建 dockerhub
之前看知乎相中了一个想法,给宝宝做一个站,上传生活的日常照片啊、视频之类的,存储肯定是在自己家里,然后做个穿透这样..开始做的时候又想着是时候接触下这些东西了,虽然公司都一点不用,但是自己没事接触下拓展下也是好的。
ubuntu 配置nginx反向代理,这里简单记录下,后续再复习..
chrome 如何查看placeholder样式以及其他伪类样式