2012-08-01 107 views
0

我試圖將nginx設置爲反向代理,用於在Apache前面提供靜態文件。我無法使用WP超級緩存配置nginx的Wordpress多站點。我有以下的配置,它不工作:使用WP超級緩存的Wordpress多站點的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." 

任何幫助是極大的讚賞!

回答

2

在您的主題目錄中編輯functions.php。

添加以下代碼:

remove_filter('template_redirect', 'redirect_canonical'); 

OR

安裝這個插件: http://wordpress.org/extend/plugins/permalink-fix-disable-canonical-redirects-pack/

+0

我決定擺脫的Apache都在一起,現在我只使用Nginx的WordPress的運行 - 自那以後沒有回頭看過。你的回答似乎解決了我的問題,所以我會繼續並接受它。我很抱歉遲到的回覆。 – darkdark 2012-12-13 09:27:05

相關問題