Welcome! Log In Create A New Profile

Advanced

Re: Virtual hosts

Maxim Dounin
June 26, 2009 08:57AM
Hello!

On Fri, Jun 26, 2009 at 05:23:28AM -0700, merlin corey wrote:

> 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

Variables are evaluated at runtime *for every request*. Dont do
that just to shorten configs.

Maxim Dounin

> 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@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
> >
> >
> >
>
Subject Author Posted

Virtual hosts

Joel Dahl June 26, 2009 05:38AM

Re: Virtual hosts

merlin corey June 26, 2009 08:23AM

Re: Virtual hosts

Maxim Dounin June 26, 2009 08:57AM

Re: Virtual hosts

meto June 26, 2009 10:11AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 170
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready