nginx.conf 反向代理配置要点是 Host zl.zxs.cn



#PROXY-START/

location ^~ /
{
    proxy_pass http://127.0.0.1:7002;
    proxy_set_header Host zl.zxs.cn;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    set $static_fileh3rdxYKt 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_fileh3rdxYKt 1;
        expires 1m;
    }
    if ( $static_fileh3rdxYKt = 0 )
    {
        add_header Cache-Control no-cache;
    }
}
#PROXY-END/

全部配置信息

server
{
    listen 80;
    server_name t.yanxuw.cn;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/n.yanxuw.cn;

    #PHP-INFO-START  PHP引用配置,可以注释或修改
    #清理缓存规则

    location ~ /purge(/.*) {
        proxy_cache_purge cache_one $host$1$is_args$args;
        #access_log  /www/wwwlogs/t.yanxuw.cn_purge_cache.log;
    }
    #引用反向代理规则,注释后配置的反向代理将无效
    include /www/server/panel/vhost/nginx/proxy/t.yanxuw.cn/*.conf;

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }

    #禁止在证书验证目录放入敏感文件
    if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
        return 403;
    }

    access_log  /www/wwwlogs/t.yanxuw.cn.log;
    error_log  /www/wwwlogs/t.yanxuw.cn.error.log;
}

frpc 客户端的配置

[root@localhost.localdomain /usr/local/frpc]
# cat frpc.toml
serverAddr = "218.244.158.28"
serverPort = 7000
auth.token = "221qing"

[[proxies]]
name = "new_zxs"
type = "tcp"
localIP = "192.168.1.254"
localPort = 80
remotePort = 7002

虚拟主机

本地虚拟主机保持和服务端的nginx反向代理的host配置一致

server {
        listen        80;
        server_name  zl.zxs.cn;
        root   "D:/phpstudy_pro/WWW/zl.zxs.cn";

....
}

proxy_set_header Host zl.zxs.cn; 这里一一对应可以改成n.zxs.cn对应本地的虚拟主机

Last modification:December 27, 2024
如果觉得我的文章对你有用,请随意赞赏