Nginx为WordPress提供404错误' / wp-admin / root

时间:2015-09-03 19:56:15

标签: wordpress nginx

我有一个与WordPress一起运行的Symfony2应用程序 - mysite.com/blog路由到我的/var/www/mysite/wordpress/目录,其他所有路由都路由到/var/www/mysite/symfony

server {
    listen 80;
    server_name mysite.com

    location / {
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/app\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        internal;
    }

    location /blog {
        root /var/www/mysite/wordpress;
        rewrite ^/blog/(.+)$ /$1 break;
        try_files $uri $uri/ /blog/index.php?q=$uri&$args;
        index index.php;

        location ~ \.php {
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
            fastcgi_split_path_info ^(?:\/blog)(.+\.php)(.*);
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
}

一切正常,但WordPress管理员(mysite.com/blog/wp-admin/)给出了404错误。访问mysite.com/blog/wp-admin/index.php按预期工作,因此看起来index index.php行无效。这可能是什么问题?

3 个答案:

答案 0 :(得分:3)

您应该使用alias代替root指令:

location ^~ /blog {
    alias /var/www/mysite/wordpress;
    index index.php;

    try_files $uri $uri/ /blog/index.php?q=$uri&$args;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_split_path_info ^(?:\/blog)(.+\.php)(.*);
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

答案 1 :(得分:0)

您需要编辑nginx服务器配置。

# WordPress single blog rules.
# Designed to be included in any server {} block.

# 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 ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)

    include fastcgi.conf;
    fastcgi_index index.php;
#   fastcgi_intercept_errors on;
    fastcgi_pass php;
}

有关此内容的更多信息: http://codex.wordpress.org/Nginx#General_WordPress_rules

答案 2 :(得分:0)

那么,如果您声称/blog/wp-admin/index.php有效,但/blog/wp-admin/没有,可能只是有条件地追加index.php,如果需要的话?

+    rewrite ^/blog/wp-admin(/)?$ /wp-admin/index.php break;
     rewrite ^/blog/(.+)$ /$1 break;

那么,日志对你的404有什么看法?我认为这可能与index指令导致“内部重定向”的事实有关,因此如果您的404最终通过/而不是/blog生成,我不会感到惊讶location org.springframework.ui.context.support.ResourceBundleThemeSource