【发布时间】:2017-03-06 23:24:26
【问题描述】:
我已经安装了一个 WP 博客,并在 nginx 服务器块配置中为其添加了一个位置块。当访问example.com/blog 的博客或example.com/blog/foo-bar-baz 之类的任何博客文章时,会提供内容,但缺少所有资产。
当我检查日志时,看起来对这些资产 URL 的所有请求都被永久重定向到根博客 URL。下面是一个来自 nginx 的访问日志的请求示例:
"GET /blog/wp-includes/js/jquery.min.js HTTP/1.1" 301 5 "https://example.com/blog/" "USER_AGENT_STRING"
下面是nginx配置:
server {
listen 80;
server_name www.example.com example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com www.example.com;
root /home/example/current/public;
index index.html index.htm;
location ~ /blog {
index index.php index.html index.htm;
fastcgi_param SCRIPT_FILENAME /var/www/blog/index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_buffers 256 128k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
}
}
如何编辑任一位置块以让 nginx 捕获对包含 /blog/wp-content/ 或 /blog/wp-includes/ 的所有 URL 的请求?我尝试添加以下位置块,但没有成功:
location ~ ^(/wp-content/|/wp-includes/)/.*\.(jpe?g|gif|css|png|js|ico|pdf|m4a|mov|mp3)$ {
root /var/www/blog;
}
【问题讨论】: