Nginx 真·反代P站 - 神代綺凛の随波逐流

之前参考大佬的教程实现了反向代理 P 站,但是遇到一些问题所以有一些修改。现在不需要了,把配置文件在这里备份一下。

galgame.link

server
{
    listen 80;
        listen 443 ssl http2;
    server_name galgame.link;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/server/stop;
}

pixiv.galgame.link

server
{
    listen 80;
        listen 443 ssl http2;
    server_name ~^([^.]+)\.galgame\.link$;
    #index index.php index.html index.htm default.php default.htm default.html;
    #root /www/server/stop;
    set $domain $1;
    if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|^$") {
    return 403;
    }
    resolver 8.8.8.8;
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Credentials true;
    add_header Access-Control-Allow-Methods GET,POST;
    location ~ .*
    {
        proxy_set_header Host $domain.pixiv.net;
        proxy_set_header Referer "https://www.pixiv.net";
        proxy_cookie_domain pixiv.net galgame.link;
        proxy_pass https://$domain.pixiv.net;
        proxy_ssl_server_name on;
        proxy_set_header Accept-Encoding "";
        proxy_redirect https://accounts.pixiv.net/ https://accounts.galgame.link/;
  
        sub_filter "i-cf.pximg.net" "i.galgame.link";
        sub_filter "pixiv.net" "galgame.link";
        sub_filter "pximg.net" "pximg.galgame.link";
        # 防止错误上报暴露站点
        sub_filter "js_error.php" "block_js_error";
        # 防止谷歌服务暴露站点,同时也可以加快网站加载
        sub_filter "www.google" "block_google";
        sub_filter_once off;
        sub_filter_types *;
    }
}

pixiv.pximg.galgame.link

server
{
    listen 80;
        listen 443 ssl http2;
    server_name ~^([^.]+)\.pximg\.galgame\.link$;
    #index index.php index.html index.htm default.php default.htm default.html;
    #root /www/server/stop;
    set $domain $1;
    if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|^$") {
    return 403;
    }
    resolver 8.8.8.8;
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Credentials true;
    add_header Access-Control-Allow-Methods GET,POST;
    location ~ .*
    {
        proxy_set_header Host $domain.pximg.net;
        proxy_set_header Referer "https://www.pixiv.net";
        proxy_pass https://$domain.pximg.net;
        proxy_ssl_server_name on;
        proxy_set_header Accept-Encoding "";

        #sub_filter "www.google.com/recaptcha" "www.recaptcha.net/recaptcha";
        sub_filter "i-cf.pximg.net" "i.galgame.link";
        sub_filter "pixiv.net" "galgame.link";
        sub_filter "pximg.net" "pximg.galgame.link";
        # 防止错误上报暴露站点
        sub_filter "js_error.php" "block_js_error";
        # 防止谷歌服务暴露站点,同时也可以加快网站加载
        sub_filter "www.google" "block_google";
        sub_filter_once off;
        sub_filter_types *;
    }
}
最后修改:2023 年 07 月 15 日
如果觉得我的文章对你有用,请随意赞赏