Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to restrict access to (and only to) using nginx. What can I try? For the moment, I managed to do that but the php file is no longer interpreted by php-fpm.

location ~ \.php($|/) {
    location ~ ^/ws(_dev)?\.php {
      auth_basic "User synchronisation webservice > please login";
      auth_basic_user_file /home/symfony/instances/somesite/ws_access;
    set  $script     $uri;
    set  $path_info  "";

    if ($uri ~ "^(.+\.php)(/.*)") {
      set  $script     $1;
      set  $path_info  $2;
    add_header X-Response-Host;
    include /etc/nginx/fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  /home/symfony/instances/somesite/service/web$script;
    fastcgi_param  PATH_INFO   $path_info;
    fastcgi_param  SCRIPT_NAME $script;
    fastcgi_param  SERVER_PORT "80";
share|improve this question
Could you please post the entire of your config? – quanta Sep 12 '12 at 13:08
No, it would be too long. But I posted what seems relevant to me. – greg0ire Sep 12 '12 at 13:20
I don't see that config part include the particular file that you want to protect. – quanta Sep 12 '12 at 14:10
the files I'm willing to protect are ws.php and ws_dev.php – greg0ire Sep 18 '12 at 10:07
up vote 1 down vote accepted

You need to repeat the fastcgi_* directives in your new location /protected.php block.

share|improve this answer
I was trying to avoid repetition, but I guess I'll do this with an include statement... +1 – greg0ire Sep 12 '12 at 13:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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