小皮面板(phpstudy) wordpress 多站点配置后 重定向的次数过多 问题

优化后的完整 Nginx 配置:

server {
    listen 443 ssl;
    server_name test.localhost;

    ssl_certificate D:/phpstudy_pro/Extensions/Nginx1.15.11/conf/ssl/test.localhost.pem;
    ssl_certificate_key D:/phpstudy_pro/Extensions/Nginx1.15.11/conf/ssl/test.localhost.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA26:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    root "D:/phpstudy_pro/WWW/test.localhost";
    index index.php index.html;

    # --- WordPress 多站点(子目录模式)核心规则 ---
    # 这段代码是关键,它会正确处理子站点的文件和路径
    if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\.php)$ $2 last;
    }
    # ---------------------------------------------

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9003;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        
        # 增加 fastcgi_param 以修复某些后台问题
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    # 可选:静态资源缓存优化
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
        expires 30d;
        access_log off;
    }
}

直接替换对应目录下的网站nginx配置文件。

By 行政