我正在使用 wordpress,它是一个多站点子文件夹配置。
- www.xyz.com is pointing to /var/www/project (Working)
- (Wordpress blog) www.xyz.com/blog is pointing to /var/www/blog (Working)
- (Wordpress blog) www.xyz.com/blog/page/2 (not working - Error given below)
因此,如果我打开页面 www.xyz.com/blog/page/2 或 www.xyz.com/blog/2015/11/15/takeup,它应该指向 /var/www/blog,而不是指向 /var/www/blog/page/2/index.php。
这是我的 Nginx 配置文件:
server {
listen 80;
server_name xyz.com;
rewrite ^/(.*)/$ /$1 permanent;
return 301 $scheme://www.xyz.com$request_uri;
}
server {
listen 80 default_server;
server_name www.xyz.com;
index index.php index.html index.htm;
location / {
root /var/www/project/public;
try_files $uri $uri/ /index.php?$query_string;
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~* \.(pdf)$ {
expires 30d;
}
location ~ \.(?:css|htc|js|js2|js3|js4)$ {
gzip_vary on;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location /blog {
alias /var/www/blog;
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
location ~ \.php$ {
#try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
}
}
我收到 404:
2016/01/23 23:27:05 [error] 32532#0: *2 "/var/www/blog/page/2/index.php" is not found (2: No such file or directory), client: 27.5.217.2, server: www.xyz.com, request: "GET /blog/page/2/ HTTP/1$
(编辑以改进错误日志格式)
答案1
我最好的猜测是,问题在于您的博客位置中的别名有问题,插入您的配置看起来很乱。我有一个在文档根目录上提供随机 PHP 的站点和博客文件夹中的 Wordpress 单个站点,这是我使用的配置的重要部分。注意,我已删除所有缓存和标头操作,并且我使用的是 HHVM 而不是 PHP。
我还有一个 WPMU 网站,它不需要任何特殊的位置块配置。我无法将子博客放在子文件夹中,这就是为什么我也安装了一个 Wordpress 单站点。
关键是你可能不需要为你的博客设置位置块,你可能只需要在根块中使用“/blog/index.php?args”的 try_files
server {
server_name example.com;
root /var/www/whatever;
# Default location to serve
location / {
# If the file can't be found try adding a slash on the end - it might be
# a directory the client is looking for. Then try the Wordpress blog URL
# this might send a few requests to PHP that don't need to go that way
try_files $uri $uri/ /blog/index.php?args;
more_clear_headers Server; more_clear_headers "Pragma"; more_clear_headers "Expires";
}
# Send HipHop and PHP requests to HHVM
location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_intercept_errors on;
fastcgi_pass php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
我不能 100% 确定这能解决您的问题,但这是我在不亲自诊断的情况下能做到的最好事情。即使这失败了,本文中的想法也会提供进一步的信息,可能有助于解决问题。