nginx多域名不同代理IP配置

map $host $proxy_destination {
    default "";
    "www.215.cn" http://61.17.9.10;
    "www.233.cn" http://61.17.9.16;
    "www.ckb.net" http://61.17.9.11;
    "www.sjp.net" http://61.17.9.15;
    "www.zsw.cn" http://61.17.9.60;
}

server
{
    listen 80 default_server;
    server_name z.xrk.site;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/z.xrk.site;

    location ^~ / {
        proxy_set_header Host $host;
        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;

        add_header X-Cache $upstream_cache_status;

        proxy_ignore_headers Set-Cookie Cache-Control expires;
        proxy_cache cache_one;
        proxy_cache_key $host$uri$is_args$args;
        proxy_cache_valid 200 304 301 302 1m;

        if ($proxy_destination != "") {
            proxy_pass $proxy_destination;
        }
    }

    #禁止访问的文件或目录
    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/z.xrk.site.log;
    error_log  /www/wwwlogs/z.xrk.site.error.log;
}

默认分类 2025-04-16 22:20:52 通过 网页 浏览(37)

共有0条评论!

发表评论

更换一道题!
放大的图片