2

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?

1 Answer 1

1

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.

7
  • With this I get a white screen with a RequestInitDocument Not Found message, with a 404 status code. Can you explain what the ^ is doing there? Commented Jan 26, 2016 at 11:05
  • I left the ; off the end of the SCRIPT_FILENAME line, does that help? Commented Jan 26, 2016 at 11:12
  • Nope, I already noticed that. Doesn't work with $fastcgi_script_name or the full path to index.php (/var/www/path/to/index.php) either. Commented Jan 26, 2016 at 11:14
  • Can you provide the contents of fastcgi_params? There is probably another header that needs overriding. Commented Jan 26, 2016 at 11:18
  • You're right, SCRIPT_FILENAME was being overwritten in the fastcgi_params file. Moved the include above the fastcgi_param lines. It's working now, but I'm 100% sure I already tried this with location ~ / instead of location ^~ /. Can you tell me what the ^ is doing there, and how it differs from leaving it out? Commented Jan 26, 2016 at 11:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.