Nginx下Frp強制重定向爲https配置

迫於家裏的路由將300M的帶寬強行降到80M的速度,因此入手了一個3205U的軟路由,果然沒有使人失望,速度飛起O(∩_∩)O哈哈~ 固然,因爲寬帶沒有公網IP因此DDNS就不能使用,轉而使用frp,在折騰的過程當中踩到了一些坑,因此記錄下來,但願能幫助有須要的同窗。nginx

frps.ini(服務端配置)

[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

frpc.ini (客戶端配置)

[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

vhosts.conf(Nginx配置)

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;
       }
}

注意!!!!!以上操做就能須要重啓服務後才能使用shell

相關文章
相關標籤/搜索