Welcome! Log In Create A New Profile

Advanced

Virtual hosts

Joel Dahl
June 26, 2009 05:38AM
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: 164
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