大网数据广告活动
服务器运维问答

Magento with nginx: different config rules for admin section

· 52CE 我爱测

I'm setting up a Magento store with nginx, and the store is working great. However, now I would like to set a higher client_max_body_size value (let's say 100m), but only for the admin section. I've already searched online, but I…

问题原文

原帖链接 · redelschaap · CC BY-SA 3.0

I'm setting up a Magento store with nginx, and the store is working great. However, now I would like to set a higher client_max_body_size value (let's say 100m), but only for the admin section.

I've already searched online, but I can't figure out how to get this to work. I'm probably misunderstanding the location blocks in this scenario, so maybe you can help me further.

I have the following server block:

server {
    listen                              80;
    server_name                         {domain};
    root                                {root};

    location / {
        index                           index.html index.php;
        try_files                       $uri $uri/ @handler;
        expires                         max;
    }

    ## These locations should be protected
    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  /. {
        return                          404;
    }

    location /api {
        rewrite     ^/api/rest          /api.php?type=rest last;
    }

    location @handler {
        rewrite     /                   /index.php;
    }

    location ~ .php/ {
        rewrite     ^(.*.php)/          $1 last;
    }

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

        expires                         off;

        fastcgi_pass                    hhvm;

        proxy_read_timeout              300s;
        proxy_connect_timeout           300s;
        fastcgi_read_timeout            300s;

        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param   MAGE_RUN_CODE   $mage_code;
        fastcgi_param   MAGE_RUN_TYPE   $mage_type;

        include                         fastcgi_params;
    }
}

Now let's say the admin is on http://domain.com/index.php/admin_section/. So I must apply a higher client_max_body_size within a location block location /index.php/admin_section/ { ... }. But when I do so, that rule is being ignored by the last location ~ .php$ { ... } block.

I know I can adjust some config rules within a if ($request_uri ~ /admin_section/) { ... } statement, but nginx won't accept the client_max_body_size directive within an if statement.

Then I tried to add a location block before and within the ~ .php$ location block and before any other location block. I also tried to copy the content of ~ .php$ block to the /index.php/admin_section/ block and put it before and after the ~ .php$ block, but nothing seems to work.

How do I get this to work?

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 3.0

The following block may work. It replicates the PHP location block (which is the usual final destination for your admin URI).

location ^~ /index.php/admin_section/ {

    client_max_body_size            100m;

    expires                         off;
    fastcgi_pass                    hhvm;

    proxy_read_timeout              300s;
    proxy_connect_timeout           300s;
    fastcgi_read_timeout            300s;

    include                         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param   MAGE_RUN_CODE   $mage_code;
    fastcgi_param   MAGE_RUN_TYPE   $mage_type;
}

I cannot test it, but hopefully there are no side-effects to break Magento.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。