【发布时间】:2018-01-15 04:34:18
【问题描述】:
我正在尝试在 NGINX 服务器上安装 WordPress Multisite。多站点是子域安装,WordPress 安装在自己的目录中。大部分都可以正常工作(前端页面、类别、帖子、管理功能等),但是当尝试导航到多站点网络管理员 (/wp-admin/network) 时,我收到 404 错误。如果我手动将我的子目录添加到 url (/wp/wp-admin/network),这将有效,但它不会自动重定向。我在我的 NGINX conf 文件中尝试了许多不同的配置,但没有成功。以下是我目前登陆的 conf 文件。
upstream php {
server unix:/var/run/php/php7.0-fpm.sock;
server 127.0.0.1:9000;
}
map $http_host $blogid {
default -999;
#Ref: http://wordpress.org/extend/plugins/nginx-helper/
include /var/www/vhosts/test.example.com/public/wp-content/uploads/nginx-helper/map.conf ;
}
# Default server configuration
#
server {
listen 80;
listen [::]:80;
server_name test.example.com *.test.example.com;
server_name_in_redirect off;
root /var/www/vhosts/test.example.com/public;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/wp(/[^/]+)?(/wp-.*) /wp$2 last;
rewrite ^/wp(/[^/]+)?(/.*\.php)$ /wp$2 last;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /wp-admin {
rewrite ^/wp-admin$ /wp/wp-admin/ redirect;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /wp/index.php?$args;
}
location /wp {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri /wp/index.php;
#fastcgi_split_path_info ^(/wp)(/.*)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
#WPMU Files
location ~ ^/files/(.*)$ {
try_files /wp/wp-content/blogs.dir/$blogid/$uri /wp/wp-includes/ms-files.php?file=$1 ;
access_log off; log_not_found off; expires max;
}
#WPMU x-sendfile to avoid php readfile()
location ^~ /blogs.dir {
internal;
alias /var/www/test.example.com/public/wp-content/blogs.dir;
access_log off; log_not_found off; expires max;
}
location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
我尝试按照 NGINX 网站上的设置说明进行操作,但没有成功:https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
我还在 NGINX 网站上读到,在 conf 文件中使用 ifs 不是一个好主意,所以我不确定下面的块是否非常合理。
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/wp(/[^/]+)?(/wp-.*) /wp$2 last;
rewrite ^/wp(/[^/]+)?(/.*\.php)$ /wp$2 last;
}
非常感谢任何帮助解决此问题。
【问题讨论】:
-
即使使用多站点,您不需要为每个站点使用不同的虚拟主机吗?
-
另外,这可能会有所帮助:digitalocean.com/community/tutorials/…
-
@Difster 据我了解,通配符 DNS 条目并在
server_name指令中包含通配符不需要每个站点的单独主机文件。至于数字海洋文章,它很棒,但不能帮助我解决在子目录中安装 WP 的问题。使用此设置,在 NGINX 服务器上,访问网络管理区域的重写不起作用。
标签: php wordpress nginx server multisite