Frp发送真实IP给Nginx

Sakura 发布于 2024-01-20 191 次阅读


Frpc配置

我的frpc版本是0.53.2

[[proxies]]
name = "ceshi"
type = "tcp"
localIP = "127.0.0.1"
localPort = 80
remotePort = 80
transport.proxyProtocolVersion = "v2"

Nginx配置

我的Nginx版本是1.24.0

server {
    listen 80 proxy_protocol;
    real_ip_header proxy_protocol;
    real_ip_recursive on;
    # 我在本机所以是127.0.0.1 但是如果是内网其他机器穿透 这里需要写frp局域网的IP地址
    set_real_ip_from 127.0.0.1;
    server_name localhost;

    location / {
        proxy_pass http://localhost:800/;
        proxy_set_header X-Real-IP $http_x_real_ip;
        proxy_set_header X-Forwarded-For $http_x_forwarded_for;
        proxy_set_header Host $http_host;

    }
}