使用 Nginx 设置两个 wordpress 服务器

使用 Nginx 设置两个 wordpress 服务器

我正在尝试设置2 个带有 Nginx 的 wordpress 服务器

两个站点均正常运行:

https://server.io/learn

https://server.io/event

但是我无法访问我创建的页面:

https://server.io/learn/2016/06/we-can-get-you-hired/

对于 /learn 或 /event,nginx 可以访问正确的内容文件夹。

/srv/server.wordpress/event/index.php > GET /event/ HTTP/1.1
/srv/server.wordpress/learn/index.php > GET /learn/ HTTP/1.1

但对于https://server.io/learn/2016/06/we-can-get-you-hired/这是错误的。

/srv/server.wordpress/index.php > GET /learn/2016/06/we-can-get-you-hired/ HTTP/1.1
                    ^
                    It doesn't go to the subfolder /learn.

错误日志:

FastCGI sent in stderr: "Primary script unknown" while reading response header 
from upstream,  request: "GET /learn/2016/06/we-can-get-you-hired/ HTTP/1.1", 
upstream: "fastcgi://127.0.0.1:9000", host: "server.io", referrer: 
"https://server.io/learn/"

这是我的配置文件:

文件:/etc/nginx/sites-enabled/server

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name server.io *.server.io;
    return 301 https://server.io$request_uri;
}
server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    server_name server.io *.server.io;
    location /learn {
        root /srv/server.wordpress;
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    location /event {
        root /srv/server.wordpress;
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        root /srv/server.wordpress;
        include fastcgi_shared.conf;
    }
}

文件:/etc/nginx/fastcgi_shared.conf

fastcgi_cache  microcache;
fastcgi_cache_key $scheme$host$request_method$request_uri;
fastcgi_cache_valid 200 304 10m;
fastcgi_cache_use_stale updating;
fastcgi_max_temp_file_size 1M;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
include        fastcgi_params;

答案1

您想要启用 WordPress 多站点并将其放入您的 ngix 配置中

if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) /wp$1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ /wp$1 last;
}

相关内容