Virtual hosts

merlin corey merlincorey at dc949.org
Fri Jun 26 16:23:28 MSD 2009


Hello,

You can use variables to set paths and such and then include files
with similar directives that may have replacements.  Not every
directive supports variables, but many do.  Redundant is not a bad
thing, because actually it is far from complex - it is quite simple!
This is a good thing.  Making a single server handle every virtual
host is much more complex and not nearly as efficient (nor flexible).

I recommend trying include directive, as you can easily put the error
page directives for example in there verbatim and save you a line.
Another way to save a line with the error page directives is to give
each host actual files in their document roots to correspond to the
error pages, then you don't need to specify a location and root
anymore PLUS your users get the benefit of custom error pages.

-- Merlin
- EN"

Remove label "NginX - EN"

Report spam

Delete

Move to


Labels


More actions

‹ Newer 7 of 471 Older ›
On Fri, Jun 26, 2009 at 2:38 AM, Joel Dahl<joel.dahl at vnode.se> wrote:
> Hi,
>
> I use the following line in nginx.conf to serve websites for a bunch of
> virtual hosts:
>
> include /usr/local/etc/nginx/vhosts/*.conf;
>
> ...and a typical configuration file for each virtual host looks like this:
>
> server {
>    listen 80;
>    server_name foobar.com;
>    rewrite ^/(.*) http://www.foobar.com permanent;
> }
>
> server {
>    listen 80;
>    server_name www.foobar.com;
>
>    location / {
>        root /home/w/www001;
>        index index.php index.html index.htm;
>    }
>
>    error_page 500 502 503 504 /50x.html;
>    location = /50x.html {
>        root /usr/local/etc/nginx/errorpages;
>    }
>
>    error_page 404 /404.html;
>    location = /404.html {
>        root /usr/local/etc/nginx/errorpages;
>    }
>
>    location ~ \.php$ {
>        fastcgi_pass 127.0.0.1:9000;
>        fastcgi_index index.php;
>        fastcgi_intercept_errors on;
>        fastcgi_param SCRIPT_FILENAME /home/w/www001$fastcgi_script_name;
>        include fastcgi_params;
>    }
>
>    location ~ /\.ht {
>        deny all;
>    }
> }
>
> I find it overly complex and redundant to include all of this in every
> *.conf file however.
>
> For example, would it be possible to put the error_page stuff in the main
> nginx.conf instead?  Like a global option for everything.
>
> Also, is it possible to use variables in the configuration file? Right now
> I'm hard-coding the domain/host name into several places in each *.conf
> file, and also the path to the actual files.  This makes it a PITA to
> maintain.
>
> I've only been using nginx for a very short time, so I'm open for any
> suggestions.  :-)
>
> --
> Joel
>
>
>





More information about the nginx mailing list