我正在尝试将nginx设置为反向代理,用于在apache之前提供静态文件。我使用WP Super Cache在为Wordpress Multisite配置nginx时遇到了麻烦。我有以下配置,但不起作用:
server {
listen 80;
# Main site domain
server_name main.com *.main.com;
# Mapped domains
server_name mapped.com www.mapped.com;
root /home/me/www/wordpress/htdocs;
access_log /home/me/www/wordpress/logs/access.log;
error_log /home/me/www/wordpress/logs/error.log;
index index.php index.html index.htm;
error_page 404 = @wordpress;
log_not_found off;
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}
############## WP MULTISITE ##############
rewrite ^/files/(.+) /wp-includes/ms-files.php?file=$1 last;
location ^~ /files/ {
rewrite ^.*/files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
}
# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
############## WP MULTISITE ##############
############## WP SUPER CACHE ############
if (-f $request_filename) {
#expires max;
break;
}
if (-d $request_filename) {
break;
}
set $supercache_file '';
set $supercache_uri $request_uri;
if ($request_method = POST) {
set $supercache_uri '';
}
if ($query_string) {
set $supercache_uri '';
}
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
}
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}
############## WP SUPER CACHE ############
location @wordpress {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
location ~ \.php$ {
try_files $uri @wordpress;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
}
加载页面时出现以下错误:
main.com : 310 - ERR_TOO_MANY_REDIRECTS
main.com/wp-admin/ : Loads WP admin page
www.main.com : Welcome to nginx!
mapped.com / www.mapped.com: 403 - Forbidden - "You don't have permission to access /index.php on this server."
非常感谢任何帮助!
答案 0 :(得分:2)
在主题目录中编辑functions.php。
添加以下代码:
remove_filter('template_redirect', 'redirect_canonical');
OR
安装此插件: http://wordpress.org/extend/plugins/permalink-fix-disable-canonical-redirects-pack/