13

I have an NGINX server with fastcgi/PHP running on it. I need to add userdirs to it, but I can't get PHP to execute the files - it just asks me if I want to download it. It does work without the userdir (e.g. it works on physibots.info/hugs.php, but not physibots.info/~kisses/hugs.php).

Config:

server {
    listen      80;
    server_name physibots.info;
    access_log  /home/virtual/physibots.info/logs/access.log;

    root /home/virtual/physibots.info/public_html;

    location ~ ^/~(.+?)(/.*)?\.php$ {
        fastcgi_param SCRIPT_FILENAME /home/$1/public_html$fastcgi_script_name;
        fastcgi_pass unix:/tmp/php.socket;
    }

    location ~ ^/~(.+?)(/.*)?$ {
        alias /home/$1/public_html$2;
        autoindex on;
    }

    location ~ \.php$ {
        try_files $uri /error.html/$uri?null;
        fastcgi_pass unix:/tmp/php.socket;
    }
}
1
  • Note: I've also tried it without the first location block, with the "fastcgi_param" line in the second location block, and without it at all, and they all have the same effect. Commented Nov 17, 2011 at 2:04

3 Answers 3

1

I've had a similar problem before on another server. My issue was that the scripts containerd <?. Taking all of that and placing php after it (like this <?php ) anywhere it appears in the script executed the files instead of downloading them.

Hope that helps.

Sign up to request clarification or add additional context in comments.

1 Comment

No, this script uses <?php ?> endings.
0

Try adding this line to the php location blocks:

fastcgi_param  REDIRECT_STATUS    200;

Btw - did you check that the php.socket actually exists?

4 Comments

It's in the server-wide conf file. And, like I said, it works perfectly for the sites that have hostnames that are explicitly stated and the root domain.
What does the error log show for requests hitting physibots.info/~kisses/hugs.php? Just a guess, but I think this may be an issue with the way you're passing the file path and script name.
It shows nothing about the file requested. The only messages in the error log are about missing favicons. Also, nothing reported by PHP in the syslog according to the error log directives in php.ini.
Are you using php-fpm? If so, make sure error_log is enabled in php-fpm.conf
0

It turns out that it was linking to /home/foo/public_html/~foo. So, a circular symlink from /home/foo/public_html/~foo back to /home/foo/public_html works like a charm. Thanks for all your help!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.