# PHP and CGI on UserDir

**URL:** <https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526>\
**Category:** NGINX\
**Created:** [December 2, 2015, 8:50am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526 "2015-12-02T08:50:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [December 2, 2015, 8:50am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/1 "2015-12-02T08:50:22Z")

</div>

Hello. I am new here.

I try to enable PHP and CGI(Perl) on UserDir (/home/user/public\_html)  
with  
nginx.  
But on my Chrome, PHP script is downloaded and CGI script shows me “404  
Not  
Found” page.  
Here’s my configurations. What is wrong with my configurations?

OS: Linux 3.10.0 / CentOS 7 64bit  
nginx version: 1.8.0

* * *

/etc/nginx/conf.d/default.conf:  
server {  
listen 80;  
server\_name localhost;  
access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log;

```
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
    root /var/www/html;
    index index.html index.htm;
}

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

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /var/www/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

location ~ (^~)*\.php$ {
    root /var/www/html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}  
location ~ (^~)\*.pl|cgi$ {  
root /var/www/html;  
fastcgi\_pass 127.0.0.1:8999;  
fastcgi\_index index.cgi;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}

```
location ~ .*~.*\.php$ {
    alias /home/$1/public_html$2;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}  
location ~ ._~._.pl|cgi$ {  
alias /home/$1/public\_html$2;  
fastcgi\_pass 127.0.0.1:8999;  
fastcgi\_index index.cgi;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}

```
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

```

}

* * *

/etc/nginx/nginx.conf:

user nginx;  
worker\_processes 1;

error\_log /var/log/nginx/error.log warn;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
log_format main '$remote_addr - $remote_user [$time_local] 

```

“$request”  
’  
'$status $body\_bytes\_sent “$http\_referer” ’  
‘"$http\_user\_agent" “$http\_x\_forwarded\_for”’;

```
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

```

}

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 8:53am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/2 "2015-12-02T08:53:17Z")

</div>

Hi Smart Goldman.

Am 29-11-2015 09:04, schrieb Smart Goldman:

> Hello. I am new here.
> 
> I try to enable PHP and CGI(Perl) on UserDir (/home/user/public\_html)  
> with nginx.  
> But on my Chrome, PHP script is downloaded and CGI script shows me “404  
> Not Found” page.  
> Here’s my configurations. What is wrong with my configurations?

Try to use nested locations.

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#location)**
>
> This directive appeared in version 1.11.8.

> ```
> index index.html index.htm;
> autoindex on;
> 
> ```

include my\_php\_config.conf;

include my\_cgi\_config.conf;

> ```
> #location ~ \.php$ {
> fastcgi_index index.php;
> include /etc/nginx/fastcgi_params;
> }
> 
> ```

This block into “my\_php\_config.conf”

> ```
> location ~ .*~.*\.php$ {
> alias /home/$1/public_html$2;
> fastcgi_pass 127.0.0.1:9000 [2];
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME
> 
> ```
> 
> $document\_root$fastcgi\_script\_name;  
> include /etc/nginx/fastcgi\_params;  
> }  
> END

This block into “my\_cgi\_config.conf”

> ```
> location ~ .*~.*\.pl|cgi$ {
> alias /home/$1/public_html$2;
> fastcgi_pass 127.0.0.1:8999 [3];
> fastcgi_index index.cgi;
> fastcgi_param SCRIPT_FILENAME
> 
> ```
> 
> $document\_root$fastcgi\_script\_name;  
> include /etc/nginx/fastcgi\_params;  
> }

END

> ```
> # deny access to .htaccess files, if Apache's document root
> # concurs with nginx's one
> 
> ```

BR Aleks

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 8:55am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/3 "2015-12-02T08:55:38Z")

</div>

On Sun, Nov 29, 2015 at 05:04:50PM +0900, Smart Goldman wrote:

Hi there,

> I try to enable PHP and CGI(Perl) on UserDir (/home/user/public\_html) with  
> nginx.  
> But on my Chrome, PHP script is downloaded and CGI script shows me “404 Not  
> Found” page.

In nginx, one requests is handled in one location.

[Module ngx\_http\_core\_module](http://nginx.org/r/location) describes how the one location is chosen  
for a particular request.

You have:

> ```
> location / {
> location ~ ^/~(.+?)(/.*)?$ {
> location = /50x.html {
> location ~ (^~)*\.php$ {
> location ~ (^~)*\.pl|cgi$ {
> location ~ .*~.*\.php$ {
> location ~ .*~.*\.pl|cgi$ {
> 
> ```

According to the description, the requests /~user/index.cgi and  
/~user/index.php are both handled in the second location there,  
which says:

> ```
> location ~ ^/~(.+?)(/.*)?$ {
> alias /home/$1/public_html$2;
> index index.html index.htm;
> autoindex on;
> 
> ```

which says “serve the file /home/user/public\_html/index.cgi (or  
index.php)  
from the filesystem, with no further processing”. And that is what you  
see – one file does not exist, do you get 404; the other file does  
exist,  
so you get it.

To make things work, you will need to arrange your location{} blocks  
so that the one that you want nginx to use to process a request, is the  
one that nginx does choose to process a request.

And then make sure that you know what mapping you want nginx to use for  
_this_ request should be handled by processing _this_ file through  
_that_  
fastcgi server (or whatever is appropriate).

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 9:09am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/4 "2015-12-02T09:09:06Z")

</div>

Hi, thank you for great help, Aleksandar L…  
I tried it.

PHP script shows me “File not found.” and outputs the following log:  
2015/11/29 05:50:15 [error] 5048#0: \*6 FastCGI sent in stderr: “Primary  
script unknown” while reading response header from upstream, client:  
119.105.136.26, server: localhost, request: “GET /~user/index.php  
HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “[host.domain.com](http://host.domain.com)”

- I do not know how to fix it…

CGI script shows me “Error: No such CGI app -  
/home//public\_html/~user/index.cgi may not exist or is not executable by  
this process.” and outputs nothing to error.log.

- /home//public\_html/~user/… I think this path is wrong and I tried to  
fix this path but I could not. /home/user/public\_html/ should be correct  
path…

2015-11-29 18:41 GMT+09:00 Aleksandar L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 9:02am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/5 "2015-12-02T09:02:39Z")

</div>

Hi Francis D. and Aleksandar L.,  
I am sorry I am late.

2015-11-29 20:10 GMT+09:00 Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Sun, Nov 29, 2015 at 05:04:50PM +0900, Smart Goldman wrote:
> 
> Hi there,
> 
> > I try to enable PHP and CGI(Perl) on UserDir (/home/user/public\_html)  
> > with  
> > nginx.  
> > But on my Chrome, PHP script is downloaded and CGI script shows me "404  
> > Not  
> > location ~ ^/~(.+?)(/._)?$ {  
> > location ~ ^/~(.+?)(/._)?$ {  
> > so that the one that you want nginx to use to process a request, is the  
> > one that nginx does choose to process a request.
> 
> And then make sure that you know what mapping you want nginx to use for  
> _this_ request should be handled by processing _this_ file through _that_  
> fastcgi server (or whatever is appropriate).
> 
> Good luck with it,

Thank you for great help!  
I did not understand /~user/index.cgi and /~user/index.php are handled  
on  
“location ~ ^/~(.+?)(/.\*)?$ {”.  
I remade /etc/nginx/conf.d/default.conf as the following:

server {  
listen 80;  
server\_name localhost;  
access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log;

```
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
    root /var/www/html;
    index index.html index.htm;
}

location ~ ^/~(.+?)(/.*)?\.(php)$ {
    alias /home/$1/public_html$2.$3;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}

```
location ~ ^/~(.+?)(/.*)?\.(pl|cgi)$ {
    alias /home/$1/public_html$2.$3;
    fastcgi_pass 127.0.0.1:8999;
    fastcgi_index index.cgi;
    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}

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

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /var/www/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

location ~ \.php$ {
    root /var/www/html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}  
location ~ .pl|cgi$ {  
root /var/www/html;  
fastcgi\_pass 127.0.0.1:8999;  
fastcgi\_index index.cgi;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}

```
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

```

}

After that, I restarted nginx. Looks like PHP (/~user/index.php) finally  
works!  
But CGI (/~user/index.cgi) says “Error: No such CGI app -  
/home/user/public\_html/index.cgi/~user/index.cgi may not exist or is not  
executable by this process.” though I don’t know why.

2015-12-01 1:47 GMT+09:00 Aleksandar L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi.
> 
> Am 29-11-2015 12:02, schrieb Smart Goldman:
> 
> > Hi, thank you for great help, Aleksandar L..  
> > I tried it.
> 
> How looks now your config?

I remade as above config.

> > /home//public\_html/~user/index.cgi may not exist or is not executable by
> 
> Due to the fact that I don’t know if you use the centos packes or the  
> nginx  
> package I suggest to install the following packages
> 
> [nginx: Linux packages](http://nginx.org/en/linux_packages.html#mainline)
> 
> and the nginx-debug and run the debug instance with the suggested settings  
> in
> 
> [A debugging log](http://nginx.org/en/docs/debugging_log.html)

I installed nginx with rpm -Uvh  
[http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm](http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm)  
and yum -y install nginx.  
Do I need to reinstall nginx for the debug?

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 9:45am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/6 "2015-12-02T09:45:56Z")

</div>

What does the nginx error log ( /var/log/nginx/error.log) say when you  
access a php page?

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 9:14am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/7 "2015-12-02T09:14:22Z")

</div>

On Wed, Dec 02, 2015 at 01:52:06AM +0900, Smart Goldman wrote:

> 2015-11-29 20:10 GMT+09:00 Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > On Sun, Nov 29, 2015 at 05:04:50PM +0900, Smart Goldman wrote:

Hi there,

> ```
> location ~ ^/~(.+?)(/.*)?\.(php)$ {
> alias /home/$1/public_html$2.$3;
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> 
> ```

Delete that line - it does nothing useful here. (It does no harm, other  
than being a distraction.)

> ```
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> 
> ```

Change that line to be just

```
fastcgi_param SCRIPT_FILENAME $document_root;

```

“alias” is a bit funny. In this context, it means that $document\_root  
corresponds to the file on the filesystem that you want the fastcgi  
server to process.

I’m a bit surprised that the current version works – perhaps your php  
config does not have

cgi.fix\_pathinfo=0

and so takes more than one guess at the file to process.

> ```
> include /etc/nginx/fastcgi_params;
> }
> 
> location ~ ^/~(.+?)(/.*)?\.(pl|cgi)$ {
> alias /home/$1/public_html$2.$3;
> fastcgi_pass 127.0.0.1:8999;
> fastcgi_index index.cgi;
> 
> ```

Delete.

> ```
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> 
> ```

Change to remove $fastcgi\_script\_name, just like the previous case.

Here, most likely php is not involved, and your fastcgi server just  
tries  
to process SCRIPT\_FILENAME, which does not name a real file right now.

> ```
> include /etc/nginx/fastcgi_params;
> }
> 
> ```

> After that, I restarted nginx. Looks like PHP (/~user/index.php) finally  
> works!  
> But CGI (/~user/index.cgi) says “Error: No such CGI app -  
> /home/user/public\_html/index.cgi/~user/index.cgi may not exist or is not  
> executable by this process.” though I don’t know why.

I think that the explanations are above, along with the one necessary  
fix  
(for cgi/pl) and the one strongly suggested fix (for php).

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 10:45am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/8 "2015-12-02T10:45:33Z")

</div>

Sorry I forgot error log.

CGI outputs 2015/11/29 04:01:07 [error] 2618#0: \*6 open()  
“/home/user/public\_html/index.cgi” failed (2: No such file or  
directory),  
client: 119.105.136.26, server: localhost, request: “GET  
/~user/index.cgi  
HTTP/1.1”, host: “[host.domain.com](http://host.domain.com)”

PHP outputs nothing to error.log.

access.log says:  
119.105.136.26 - - [29/Nov/2015:04:01:07 -0500] “GET /~user/index.cgi  
HTTP/1.1” 404 570 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64)  
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86  
Safari/537.36”  
119.105.136.26 - - [29/Nov/2015:04:08:23 -0500] “GET /~user/index.php  
HTTP/1.1” 200 20 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0;  
rv:11.0) like Gecko”

2015-11-29 17:28 GMT+09:00 Anoop A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 9:45am UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/9 "2015-12-02T09:45:56Z")

</div>

Hi.

Am 29-11-2015 12:02, schrieb Smart Goldman:

> Hi, thank you for great help, Aleksandar L..  
> I tried it.

How looks now your config?

> /home//public\_html/~user/index.cgi may not exist or is not executable  
> by  
> this process." and outputs nothing to error.log.
> 
> - /home//public\_html/~user/… I think this path is wrong and I tried  
> to  
> fix this path but I could not. /home/user/public\_html/ should be  
> correct  
> path..

Please run the debug log to see more.

> **[A debugging log](http://nginx.org/en/docs/debugging_log.html)**

Due to the fact that I don’t know if you use the centos packes or the  
nginx package I suggest to install the following packages

> **[nginx: Linux packages](http://nginx.org/en/linux_packages.html#mainline)**

and the nginx-debug and run the debug instance with the suggested  
settings in

> **[A debugging log](http://nginx.org/en/docs/debugging_log.html)**

BR Aleks

---

<div class="post-metadata">

**Author:** ![Smart\_Goldman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Smart\_Goldman](https://www.ruby-forum.com/u/Smart_Goldman)\
**Post date:** [December 2, 2015, 2:04pm UTC](https://www.ruby-forum.com/t/php-and-cgi-on-userdir/243526/10 "2015-12-02T14:04:47Z")

</div>

Hi Francis,

2015-12-02 5:50 GMT+09:00 Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Delete that line - it does nothing useful here. (It does no harm, other  
> than being a distraction.)
> 
> > ```
> > fastcgi_param SCRIPT_FILENAME
> > 
> > ```

$document\_root$fastcgi\_script\_name;

> config does not have
> 
> cgi.fix\_pathinfo=0

This value is commented out.  
$ grep cgi.fix\_pathinfo php.ini  
; cgi.fix\_pathinfo provides _real_ PATH\_INFO/PATH\_TRANSLATED support for  
CGI. PHP’s  
;cgi.fix\_pathinfo=1  
I’ve never edited php.ini.

> Delete.
> 
> > ```
> > fastcgi_param SCRIPT_FILENAME
> > 
> > ```

$document\_root$fastcgi\_script\_name;

> > works!  
> > But CGI (/~user/index.cgi) says “Error: No such CGI app -  
> > /home/user/public\_html/index.cgi/~user/index.cgi may not exist or is not  
> > executable by this process.” though I don’t know why.
> 
> I think that the explanations are above, along with the one necessary fix  
> (for cgi/pl) and the one strongly suggested fix (for php).
> 
> Good luck with it,

Great!! Both of CGI and PHP finally works!!  
I made configuration file by copying from configuration file which I  
found  
from somewhere and I did not understand what fastcgi\_param means.  
Thanks so much for your help!

I put successful configuration here again for future use.

/etc/nginx/conf.d/default.conf  
server {  
listen 80;  
server\_name localhost;  
access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log debug;

```
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
    root /var/www/html;
    index index.html index.htm;
}

location ~ ^/~(.+?)(/.*)?\.(php)$ {
    alias /home/$1/public_html$2.$3;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root;
    include /etc/nginx/fastcgi_params;
}

location ~ ^/~(.+?)(/.*)?\.(pl|cgi)$ {
    alias /home/$1/public_html$2.$3;
    fastcgi_pass 127.0.0.1:8999;
    fastcgi_index index.cgi;
    fastcgi_param SCRIPT_FILENAME $document_root;
    include /etc/nginx/fastcgi_params;
}

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

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /var/www/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

location ~ \.php$ {
    root /var/www/html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}  
location ~ .pl|cgi$ {  
root /var/www/html;  
fastcgi\_pass 127.0.0.1:8999;  
fastcgi\_index index.cgi;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}
