# Avice for my vhost configuration

**URL:** <https://www.ruby-forum.com/t/avice-for-my-vhost-configuration/236102>\
**Category:** NGINX\
**Created:** [August 5, 2013, 11:44pm UTC](https://www.ruby-forum.com/t/avice-for-my-vhost-configuration/236102 "2013-08-05T23:44:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 5, 2013, 11:44pm UTC](https://www.ruby-forum.com/t/avice-for-my-vhost-configuration/236102/1 "2013-08-05T23:44:54Z")

</div>

Hello,

I plan to configure my nginx server with a couple of vhosts.  
For each of them I want:

- to use php
- deny access begining by a dot
- not logging access to favicon

So my configuration would look like that  
server {  
…

location ~ .php$ {  
root /var/www/htdocs/sites/expertinet;  
fastcgi\_pass unix:/tmp/php.sock;

# fastcgi\_pass 127.0.0.1:9000;

fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}

location ~ /. {  
access\_log off;  
log\_not\_found off;  
deny all;  
}

location = /favicon.ico {  
return 204;  
access\_log off;  
log\_not\_found off;  
expires 30d;  
}  
}

This in each of my virtual host configuration. This is very redundant.  
For example if I want to use tcp socket for fastcgi\_pass, I need to edit  
every single vhost configuration.

What are you advices to avoid this ? What is the recommended practice ?  
Someone adviced my to use include… Could you show me an example ?

Thank you

---

<div class="post-metadata">

**Author:** ![Mik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f14d63/32.png) [@Mik\_J](https://www.ruby-forum.com/u/Mik_J)\
**Post date:** [August 6, 2013, 2:42am UTC](https://www.ruby-forum.com/t/avice-for-my-vhost-configuration/236102/2 "2013-08-06T02:42:16Z")

</div>

Yup, include is the way I would do that personally.

Documentation: [Core functionality](http://nginx.org/en/docs/ngx_core_module.html#include)  
The funny thing is you already are using the ‘include’ directive: look  
at  
your ‘include fastcgi\_params;’ line. There must be a ‘fastcgi\_params’  
file  
in your configuration directory…  
That probably comes from the part you copied/pasted from the sample doc.

The way to go would be to put the redundant configuration part in it  
then  
call it wherever necessary in the vhosts conf.  
The docs tell you that include can be used in any context you wish, you  
just need to decide on the granularity.

## Hope I helped,

_B. R._

---

<div class="post-metadata">

**Author:** ![Mik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f14d63/32.png) [@Mik\_J](https://www.ruby-forum.com/u/Mik_J)\
**Post date:** [August 6, 2013, 10:10am UTC](https://www.ruby-forum.com/t/avice-for-my-vhost-configuration/236102/3 "2013-08-06T10:10:54Z")

</div>

— Original message —  
From: “Mik J” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: 6 August 2013, 00:44:37

> # fastcgi\_pass 127.0.0.1:9000;
> 
> }
> 
> What are you advices to avoid this ? What is the recommended practice ?
> 
> Someone adviced my to use include… Could you show me an example ?

```
  You must read docs. 

```

> **[Core functionality](http://nginx.org/en/docs/ngx_core_module.html#include)**
>
> Includes another file, or files matching the specified mask, into configuration. Included files should consist of syntactically correct directives and blocks.

For you:

> location ~ .php$ {  
> root /var/www/htdocs/sites/expertinet; ← you should avoid this,  
> read [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Pitfalls)

include my\_fastcgi\_params;

> include  
> fastcgi\_params;  
> }

in my\_fastcgi\_params:

fastcgi\_pass unix:/tmp/php.sock;

# fastcgi\_pass 127.0.0.1:9000;

fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;

–  
Cheers,

---

<div class="post-metadata">

**Author:** ![Mik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f14d63/32.png) [@Mik\_J](https://www.ruby-forum.com/u/Mik_J)\
**Post date:** [August 6, 2013, 9:41pm UTC](https://www.ruby-forum.com/t/avice-for-my-vhost-configuration/236102/4 "2013-08-06T21:41:29Z")

</div>

Hello, Thank you both for your answer.

I did read the page  
[Core functionality](http://nginx.org/en/docs/ngx_core_module.html#include) but I sometimes  
get confused how to put things in order exactly.

I removed the root stanza in the location block.

As for fastcgi\_params I already have the line  
fastcgi\_param SCRIPT\_NAME $fastcgi\_script\_name;

which looks like the one you wrote  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
in your my\_fastcgi\_params

What is the difference between those two ? I didn’t see SCRIPT\_NAME in  
the HttpFastcgiModule documentation whereas SCRIPT\_FILENAME is defined  
by “Parameter SCRIPT\_FILENAME is used by PHP for determining the name of  
script to execute”

Also, where should I put my include files ? It seems that /etc/nginx is  
the default location. Or you put them in another directory ?

Cheers
