首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WordPress子域多站点Nginx媒体库

WordPress子域多站点Nginx媒体库
EN

Stack Overflow用户
提问于 2011-06-06 07:01:44
回答 1查看 1.9K关注 0票数 0

我在Nginx上运行带有子域和域映射的WordPress multisite。除了媒体库之外,一切似乎都运行正常。文件被上传到wp-content/blogs.dir/BLOGID/files并正确显示,但WordPress重写规则不起作用。它试图访问的URL是http://mydomain.com/files/2011/06/image.jpg,但一直收到404错误

nginx conf文件如下所示。

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2012-01-12 14:52:16

如果您仍然不能正常工作,请删除这些行...

代码语言:javascript
复制
 # 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;
}

并在您的位置中插入以下代码/{} ...

代码语言:javascript
复制
rewrite files/(.+) /wp-includes/ms-files.php?file=$1 last;

希望这对有同样问题的人有所帮助!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6246490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档