3

In my php.ini, I have disabled allow_url_fopen. I would like to enable it for my /example directory as shown below, but it does not work. However, if I move the directive to allow it from /example to the ~.php$ location above it, then it works fine. I'm thinking that the /example location block is never processed. Any ideas how to allow url fopen to work only in the /example directory?

server {
  location ~\.php$ {
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
  }

  location /example {
    fastcgi_param PHP_ADMIN_VALUE "allow_url_fopen=1";
  }
}
dstach
  • 119
  • 1
  • 2
  • 8

1 Answers1

4

nginx chooses one location to process the request. See this document for details.

The regular expression location block takes precedence over regular prefix location blocks, so any URI ending with .php will be processed by your location ~\.php$ block, irrespective of whether or not it begins with /example. See this document for details.

If you want to create a location that sends additional fastcgi parameters, you will need to include all required fastcgi directives.

For example:

location ~\.php$ {
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
}

location ^~ /example {
    location ~\.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param PHP_ADMIN_VALUE "allow_url_fopen=1";
    }
}
Richard Smith
  • 45,711
  • 6
  • 82
  • 81