Virtual hosts
    Joel Dahl 
    joel.dahl at vnode.se
       
    Fri Jun 26 13:38:35 MSD 2009
    
    
  
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