1

I want to change fastcgi_param only for specific routes as described below:

server {
    # (...)

    # PHP entry point for main application
    location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
        try_files $uri =404;
        fastcgi_pass   fastcgi_backend;
        fastcgi_buffers 1024 4k;

        fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
        fastcgi_param  PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;

        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # Changed memory_limit for that path
    location ^~ ^/rewritten_path {
        # Change memory_limit only for all routes: example.com/rewritten_path/...
        fastcgi_param  PHP_VALUE "memory_limit=1024M \n max_execution_time=18000";
        # Allow /index.php$is_args$args
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # (...)
}
0

You could define a new value using fastcgi_param within another location block, but you will need to include the complete context, all the other fastcgi_param statements and the fastcgi_pass statement.

It would be simpler to use a variable within the existing location block. You could define the variable using a map. See this document for details.

For example:

map $request_uri $php_value {
  default             "memory_limit=756M \n max_execution_time=18000";
  ~^/rewritten_path   "memory_limit=1024M \n max_execution_time=18000";
}
server {
    ...
    location ... {
        try_files $uri =404;
        fastcgi_pass   fastcgi_backend;
        include        fastcgi_params;
        ...
        fastcgi_param  PHP_VALUE  $php_value;
        ...
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.