How to configure Frp to force redirect to https under Nginx

WBOY
Release: 2023-05-24 15:34:14
forward
1526 people have browsed it

frps.ini (server configuration)

[common]
bind_port = 5443
kcp_bind_port = 5443

vhost_http_port = 8080
vhost_https_port = 4443

# frp的服务器指示面板配置
admin_addr = frp.test.com
dashboard_port = 6443
dashboard_user = test
dashboard_pwd = test

log_file = ./frps.log

# trace, debug, info, warn, error
log_level = info

log_max_days = 3

# auth token 可自主生成一些字符串
token = sfsfgsdgsdgsgddgsg

tcp_mux = true

max_pool_count = 50

# 用户自定义域名
subdomain_host = frp.test.com
Copy after login

frpc.ini (client configuration)

[common]
# 远程服务器ip地址
server_addr = 8.8.8.8
server_port = 5443
token = sfsfgsdgsdgsgddgsg
tls_enable = true

[lede]
type = http
local_ip = 10.10.10.1
local_port = 80
# 这里的值最终会被解析为lede.frp.test.com(需要在你的域名服务器做指向你自己公网服务器的*.frp.test.com的
# 域名泛解析)
subdomain = lede
use_encryption = false         
use_compression = true

# http基础认证可以不填写
http_user = test
http_pwd = test
Copy after login

vhosts.conf (nginx configuration)

server {
 listen 80;
 listen 443 ssl http2;
 ssl_certificate /usr/local/nginx/conf/ssl/lede.frp.test.com.crt;
 ssl_certificate_key /usr/local/nginx/conf/ssl/lede.frp.test.com.key;
 ssl_protocols tlsv1 tlsv1.1 tlsv1.2;
 ssl_ciphers eecdh+chacha20:eecdh+aes128:rsa+aes128:eecdh+aes256:rsa+aes256:eecdh+3des:rsa+3des:!md5;
 ssl_prefer_server_ciphers on;
 ssl_session_timeout 10m;
 ssl_session_cache builtin:1000 shared:ssl:10m;
 ssl_buffer_size 1400;
 add_header strict-transport-security max-age=15768000;
 ssl_stapling on;
 ssl_stapling_verify on;
 server_name lede.frp.okuka.com;
 access_log /data/wwwlogs/lede.frp.test.com_nginx.log combined;

 if ($ssl_protocol = "") { return 301 https://$host$request_uri; }

 location / {
      proxy_pass http://127.0.0.1:8080;#端口号一定要和frps.ini的vhost_http_port一致 
      proxy_set_header host $host;
      proxy_set_header x-real-ip 8.8.8.8;#这里填写你的公网服务器ip 
      proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
    }
}
Copy after login

Attention! ! ! ! ! The above operations require restarting the service before you can use it

The above is the detailed content of How to configure Frp to force redirect to https under Nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template