same config for two virtual hosts (except hostname / certificate)

António P. P. Almeida appa at perusio.net
Wed Nov 23 23:43:01 UTC 2011


On 23 Nov 2011 23h35 WET, gelonida at gmail.com wrote:

> On 11/24/2011 12:30 AM, António P. P. Almeida wrote:
>> On 23 Nov 2011 23h21 WET, gelonida at gmail.com wrote:
>>>>
>>>> My suggestion is for you to place the common things in both
>>>> vhosts in a file, e.g., my_common_config.conf and do an include
>>>> in each vhost:
>>>>
>>>> server_1.mysite.net.conf
>>>> server_2.mysite.net.conf
>>>
>>> Where would you place my_common_config.conf?
>>> would you clutter /etc/nginx with it or create a subdir like
>>> /etf/nginx/sites-baseconfig
>>> would you then just do an include with a relative path like
>>> include ../my_common_config.conf ?
>>
>> I prefer to have it under the sites-available directory. Because is
>> something specific to one or more of the enabled sites.
>>
>> There's in Debian a /etc/nginx/conf.d dir but I never use it. I put
>> all generic stuff in /etc/nginx and site specific stuff under
>> /etc/nginx/sites-available.
>>
>> I always name the vhost config files with names that identify it
>> explicitly, .e.g, www.example.com.conf. This way there's no risk in
>> confusing vhost config with other files that have directives that
>> can be used in several vhosts.
>>
> Yes combined with your naming style this should be clear enough.
> I assume you will just symlink the vhosts file to sites available.
> and the include will thus be something like
> include ../sites-available/common_settings.conf, right?

Nope. I do nginx_ensite www.example.com.conf 

This creates a symlink:

ls -la /etc/sites-enabled

www.example.com.conf -->
/etc/nginx/sites-available/www.example.com.conf

Of course you must have a line like:

include /etc/nginx/sites-enabled/*; 

in your nginx.conf

The common_settings.conf is included in the www.example.com.conf file:

include sites-available/common_settings.conf;

It only makes sense to symlink vhost configs.

--- appa



More information about the nginx mailing list