WordPress Субдомен Мультисайт Медиа Библиотека Nginx - PullRequest
0 голосов
/ 06 июня 2011

Я использую мультисайт WordPress с поддоменами и сопоставлением доменов в Nginx. Кажется, все работает правильно, за исключением библиотеки мультимедиа. Файлы загружаются в wp-content / blogs.dir / BLOGID / files и отображаются правильно, но правила переписывания WordPress не работают. URL, к которому он пытается получить доступ: http://mydomain.com/files/2011/06/image.jpg, но он продолжает получать ошибку 404

Файл 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;
}

1 Ответ

2 голосов
/ 12 января 2012

Если у вас все еще не работает эта функция, удалите эти строки ...

 # 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;

Надеюсь, это поможет тому, у кого такая же проблема!

...