Magento 与 nginx try_files 不工作

Magento 与 nginx try_files 不工作

我有一台运行 Magento 电子商务应用程序的服务器,它使用 Nginx 运行。最近我在文档根目录下安装了一个 Wordpress 博客,如下所示:http://example.com/blog 当我处理 wordpress 的永久链接时,我发现配置文件中的 try_files 指令无法正常工作。这是我的配置文件:

server {
    listen www.xxx.com:80;
    server_name www.xxx.com;
    root /home/abc/www;
    access_log /home/abc/log/access.log;
    error_log /home/abc/log/error.log;
    index index.php index.html index.htm;

    if ($request_uri ~ " ") {
        return 444;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 7d;
    }

    location /blog/ {
        try_files $uri $uri/ /blog/index.php?$args;
    }

    location ~* \.(html|htm)$ {
        expires 1d;
    }

    location / {
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        #expires 30d;                  ## Assume all files are cachable
    }

    ## These locations would be hidden by .htaccess normally
    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }

    location /var/export/ {                ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd;     ## See /etc/nginx/htpassword
        autoindex            on;
    }

    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    if (!-e $request_filename) { rewrite / /index.php last; }

    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        include fastcgi_params;
    }

}

我尝试删除 `if (!-e $request_filename) { rewrite / /index.php last; } 但之后我前端的所有链接都变成了 404。

另一件事是,我在同一台服务器上有一个临时站点,删除该行代码后,它运行良好。我很困惑,不知道这里出了什么问题。有人能帮忙吗?如果需要,我会发布更多详细信息。只要告诉我就行。非常感谢。

相关内容