# Conversion of PHP single machine setup to nginx/php residing on different boxes

**URL:** <https://www.ruby-forum.com/t/conversion-of-php-single-machine-setup-to-nginx-php-residing-on-different-boxes/220347>\
**Category:** NGINX\
**Created:** [June 6, 2012, 3:18pm UTC](https://www.ruby-forum.com/t/conversion-of-php-single-machine-setup-to-nginx-php-residing-on-different-boxes/220347 "2012-06-06T15:18:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 6, 2012, 3:18pm UTC](https://www.ruby-forum.com/t/conversion-of-php-single-machine-setup-to-nginx-php-residing-on-different-boxes/220347/1 "2012-06-06T15:18:07Z")

</div>

Hello,

I am trying to implement  
[http://www.howtoforge.com/installing-nginx-with-](http://www.howtoforge.com/installing-nginx-with-)  
php5-and-mysql-support-on-debian-squeeze , where the nginx server config  
looks like so:

> ```
> root /usr/share;
> #
> #error_page 500 502 503 504 /50x.html;
> #location = /50x.html {
> # root /var/www/nginx-default;
> #}
> # 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$ {
> try_files $uri =404;
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME
> 
> ```

/var/www$fastcgi\_script\_name;

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

My setup looks slightly different from the one used for that howto, as I  
have a host/firewall/nginx box that houses client applications in lxc-  
containers. I am having trouble in setting up the ~ .php$ bit in that  
context. My config lookis like this:

> server {  
> listen 443;  
> server\_name XXX;  
> client\_max\_body\_size 40M;  
> # SSL is using CACert credentials  
> ssl on;  
> ssl\_certificate /etc/ssl/private/cacert.XXX.org.pem;  
> ssl\_certificate\_key  
> /etc/ssl/private/cacert.XXX.org\_privatkey.pem;  
> ssl\_session\_timeout 5m;  
> ssl\_protocols SSLv3 TLSv1;  
> ssl\_ciphers ALL:!ADH:!EXPORT56:!LOW:RC4+RSA:+HIGH:+MEDIUM:+SSLv3:  
> +EXP;  
> ssl\_prefer\_server\_ciphers on;  
> # Proxy the “feng-container” lxc container  
> location / {  
> proxy\_pass [http://10.10.10.3:80/](http://10.10.10.3:80/);  
> }  
> location ~ .php$ {  
> try\_files $uri =404;  
> fastcgi\_pass 10.10.10.3:9000;  
> fastcgi\_index index.php;  
> fastcgi\_param SCRIPT\_FILENAME  
> [http://10.10.10.3:80/$fastcgi\_script\_name](http://10.10.10.3:80/$fastcgi_script_name);  
> include fastcgi\_params;  
> }  
> }

The “/” bit works, but php location gives me “404” despite ports 80/9000  
being open …

Can anyone nudge me into the right direction on how to proceed here?

Thanks, Joh

---

<div class="post-metadata">

**Author:** ![Johannes\_Graumann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@Johannes\_Graumann](https://www.ruby-forum.com/u/Johannes_Graumann)\
**Post date:** [June 6, 2012, 3:35pm UTC](https://www.ruby-forum.com/t/conversion-of-php-single-machine-setup-to-nginx-php-residing-on-different-boxes/220347/2 "2012-06-06T15:35:04Z")

</div>

On Wed, Jun 06, 2012 at 04:18:10PM +0300, Johannes Graumann wrote:

Hi there,

> > ```
> > location ~ \.php$ {
> > try_files $uri =404;
> > 
> > ```

try\_files refers to local files only. [Module ngx\_http\_core\_module](http://nginx.org/r/try_files)

You probably don’t want it here at all.

> > ```
> > fastcgi_pass 10.10.10.3:9000;
> > fastcgi_index index.php;
> > fastcgi_param SCRIPT_FILENAME
> > 
> > ```
> 
> [http://10.10.10.3:80/$fastcgi\_script\_name](http://10.10.10.3:80/$fastcgi_script_name);

SCRIPT\_FILENAME is a parameter that the fastcgi server will read, and  
it will expect it to refer to a file on its filesystem that it should  
load and process.

So: if the client requests the url /one/two.php, what file on the  
10.10.10.3 server do you want that to correspond to? (From the  
perspective  
of the fasctcgi server, in case it is chroot’ed.)

Make SCRIPT\_FILENAME be that filename.

All the best,

## f

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

---

<div class="post-metadata">

**Author:** ![Johannes\_Graumann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@Johannes\_Graumann](https://www.ruby-forum.com/u/Johannes_Graumann)\
**Post date:** [June 6, 2012, 10:10pm UTC](https://www.ruby-forum.com/t/conversion-of-php-single-machine-setup-to-nginx-php-residing-on-different-boxes/220347/3 "2012-06-06T22:10:53Z")

</div>

Francis D. wrote:

> 10.10.10.3 server do you want that to correspond to? (From the perspective  
> of the fasctcgi server, in case it is chroot’ed.)
> 
> Make SCRIPT\_FILENAME be that filename.

Thanks a lot for your pointers, which nudged me in the right direction.  
After also finding [Nginx Library](http://nginxlibrary.com/resolving-no-input-file-)  
specified-error/ I came up with the following, which is working (a  
“info.php” script at the documentroot containing a call to “phpinfo()”  
is  
rendered properly and the output has “Server API: CGI/FastCGI”):

> server {  
> listen 443;  
> server\_name [XXX.org](http://XXX.org) XXX;  
> client\_max\_body\_size 40M;  
> # SSL is using CACert credentials  
> ssl on;  
> ssl\_certificate /etc/ssl/private/cacert.XXX.org.pem;  
> ssl\_certificate\_key  
> /etc/ssl/private/cacert.XXX.org\_privatkey.pem;  
> ssl\_session\_timeout 5m;  
> ssl\_protocols SSLv3 TLSv1;  
> ssl\_ciphers ALL:!ADH:!EXPORT56:!LOW:RC4+RSA:+HIGH:+MEDIUM:  
> +SSLv3:+EXP;  
> fastcgi\_param SCRIPT\_FILENAME  
> $document\_root$fastcgi\_script\_name;  
> include fastcgi\_params;  
> }  
> }

Thank you. Joh

---

<div class="post-metadata">

**Author:** ![Johannes\_Graumann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@Johannes\_Graumann](https://www.ruby-forum.com/u/Johannes_Graumann)\
**Post date:** [June 24, 2012, 12:34pm UTC](https://www.ruby-forum.com/t/conversion-of-php-single-machine-setup-to-nginx-php-residing-on-different-boxes/220347/4 "2012-06-24T12:34:08Z")

</div>

Hello Again,

Johannes Graumann wrote:

> > # SSL is using CACert credentials
> > 
> > root /var/www/;  
> > }  
> > }

As I wrote, this works fine for a plain “index.php” containing  
“phpinfo()”.  
I now want to use the setup to run fengoffice along the lines of  
[http://www.howtoforge.com/how-to-set-up-a-feng-office-suite-web-server-on-](http://www.howtoforge.com/how-to-set-up-a-feng-office-suite-web-server-on-)  
ubuntu-server-10.10 . So I change the above setup to point at root  
“/var/www/www.feng.graumannschaft.org/web/” which is where fenoffice’s  
index.php resides on 10.10.10.3. THis however does not work and the  
browser  
pointed at the urls reports

> Unable to connect  
> Iceweasel can’t establish a connection to the server at 10.10.10.3.

I seem to be missing rewriting somewhere, but no prowling the internet  
has  
given me an answer that will work. Can someone nudge me into the right  
direction (again) how to fix this?

Thanks for any pointers, Joh
