2011-06-05 66 views
0

我在Nginx上運行帶有子域名和域名映射的WordPress多站點。除媒體庫外,一切似乎都正常工作。文件被上傳到wp-content/blogs.dir/BLOGID /文件並正確顯示,但WordPress重寫規則不起作用。它嘗試訪問的URL是http://mydomain.com/files/2011/06/image.jpg,但它總是收到404錯誤WordPress Subdomain多站點Nginx媒體庫

nginx conf文件如下。

server 
{ 
    listen  80; 
    server_name *.mydomain.com; 
    index index.html index.htm index.php default.html default.htm default.php; 
    root /home/wwwroot/mydomain.com; 

    # WordPress multisite sub-domain rules. 
    # Designed to be included in any server {} block. 

    error_page 404 = @wordpress; 
    log_not_found off; 

    # This order might seem weird - this is attempted to match last if rules below fail. 
    # http://wiki.nginx.org/HttpCoreModule 
    location/{ 
     try_files $uri $uri/ /index.php?$args; 
    } 

    # Add trailing slash to */wp-admin requests. 
    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 

    # Directives to send expires headers and turn off 404 error logging. 
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
     expires 24h; 
     log_not_found off; 
    } 

    # Pass uploaded files to wp-includes/ms-files.php. 
    rewrite /files/$ /index.php 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; 
    } 

    location @wordpress { 
     fastcgi_pass unix:/tmp/php-cgi.sock; 
     fastcgi_param SCRIPT_FILENAME $document_root/index.php; 
     include fcgi.conf; 
     fastcgi_param SCRIPT_NAME /index.php; 
    } 

    # Pass all .php files onto a php-fpm/php-fcgi server. 
    location ~ \.php$ { 
     # Zero-day exploit defense. 
     # http://forum.nginx.org/read.php?2,88845,page=3 
     # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi. 

     try_files $uri @wordpress; 

     #fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_index index.php; 
     fastcgi_pass unix:/tmp/php-cgi.sock; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    # fastcgi_intercept_errors on; 
     include fcgi.conf; 
    } 

    # if the requested file exists, return it immediately 
    if (-f $request_filename) { 
     break; 
    } 

    ## W3 Total CACHE BEGIN 
    set $totalcache_file ''; 
    set $totalcache_uri $request_uri; 

    if ($request_method = POST) { 
     set $totalcache_uri ''; 
    } 

    # Using pretty permalinks, so bypass the cache for any query string 
    if ($query_string) { 
     set $totalcache_uri ''; 
    } 

    if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_") { 
     set $totalcache_uri ''; 
    } 

    # if we haven't bypassed the cache, specify our totalcache file 
    if ($totalcache_uri ~ ^(.+)$) { 
     set $totalcache_file /wp-content/w3tc-$http_host/pgcache/$1/_default_.html; 
    } 

    # only rewrite to the totalcache file if it actually exists 
    if (-f $document_root$totalcache_file) { 
     rewrite ^(.*)$ $totalcache_file break; 
    }     

    ##W3 Total CACHE END 

    # all other requests go to WordPress 
    if (!-e $request_filename) { 
     rewrite . /index.php last; 
    } 

    log_format mydomain.com '$remote_addr - $remote_user [$time_local] $request ' 
    '$status $body_bytes_sent $http_referer ' 
    '$http_user_agent $http_x_forwarded_for'; 
    access_log /home/wwwlogs/mydomain.com.log mydomain.com; 
} 

回答

2

如果你還沒有得到這個工作,請刪除這些行...

# Pass uploaded files to wp-includes/ms-files.php. 
rewrite /files/$ /index.php last; 

location ^~ /files/ { 
    rewrite ^.*/files/(.+)$ /wp-includes/ms-files.php?file=$1 last; 
} 

,插入你的位置/ {}內將以下代碼...

rewrite files/(.+) /wp-includes/ms-files.php?file=$1 last; 

希望這可以幫助有同樣問題的人!