假设四个域名需要部署
1.域名一
www.test01.com 80 /web/www/test01
2.域名二
www.test02.com 80 /web/www/test02
3.域名三 指定端口
www.test03.com 8080 /web/www/test03
4.域名四 指定IP
www.test04.com 127.0.0.1:80 /web/www/test04
nginx 虚拟主机配置如下
server {
listen 80;
server_name www.test01.com;
access_log logs/test01.access.log main;
error_log logs/test01.error.log info;
location / {
root /web/www/test01;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /web/www/test02;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
server {
listen 80;
server_name www.test02.com;
access_log logs/test02.access.log main;
error_log logs/test02.error.log info;
location / {
root /web/www/test02;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /web/www/test02;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
server {
listen 8080;
server_name www.test03.com;
access_log logs/test03.access.log main;
error_log logs/test03.error.log info;
location / {
root /web/www/test03;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /web/www/test03;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
server {
listen 127.0.0.1:80;
server_name www.test04.com;
access_log logs/test04.access.log main;
error_log logs/test04.error.log info;
location / {
root /web/www/test04;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /web/www/test04;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
参数含义:
server_name #虚拟主机的域名,可以写多个域名,类似于别名,可以配置成如下
server_name www.test01.com www.test02.com www.test03.com
listen 80 #监听ip 和端口,这边仅仅只有端口,表示当前服务器所有ip 的80 端口,如果只想监听127.0.0.1的80,写法如下:
listen 127.0.0.1:80
root /web/www/test01 #站点根目录,网站文件路径
index index.php index.html index.htm; #索引文件
access_log logs/test04.access.log main; #访问日志
error_log logs/test04.error.log info; #错误日志