
无需加好友免费技术支持
在我们选购一个单独的服务器时,假如我们只放一个网站,大家有点儿消耗。我们能摆放好几个网址,以最大程度地利用自身网络资源室内空间。以下属于我融合一些在线教程亲身测试一般情况。
根据环境测试:Centos7
假定:
IP地址: 222.123.12.14
网站域名1 abc.com 放到 /www/abc
网站域名2 def.com 放到 /www/def
配备 nginx virtual hosting 一般思路和流程如下所示:
把2个网站 abc.com, def.com 放进 nginx 可浏览的文件目录 /www/
为每一个个网站 nginx 配置文件 abc.com.conf,def.com.conf,
并把配置文件放进 /etc/nginx/vhosts/
之后在 /etc/nginx.conf 里边加一句 include 包含流程2创建的所有配置文件(应用) * 号)
重新启动 nginx
实际全过程
实际配备步骤如下所示:
1、在 /etc/nginx 下创建 vhosts 文件目录
mkdir /etc/nginx/vhosts
2、在 /etc/nginx/vhosts/ 在里面创建一个名字 abc.com.conf 拷贝下列文件
server {
listen 80;
server_name abc.com abc.com;
access_log /www/access_ abc.log main;
location / {
root /www/abc.com;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/abc.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
3、在 /etc/nginx/vhosts/ 在里面创建一个名字 def.com.conf 拷贝下列文件
server {
listen 80;
server_name def.com def.com;
access_log /www/access_ abc.log main;
location / {
root /www/def.com;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/def.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
4、开启 /etc/nginix.conf 在对应的部位加上文件 include 包含以上2个文件
user nginx;
worker_processes 1;
# main server error log
error_log /var/log/nginx/error.log ;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
# main server config
http {
include mime.types;
default_type application/octet-stream;
log_format main "$remote_addr - $remote_user [$time_local] $request "
""$status" $body_bytes_sent "$http_referer" "
""$http_user_agent" "$http_x_forwarded_for"";
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
access_log /var/log/nginx/access.log main;
server_name_in_redirect off;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
# 配置文件包含云虚拟主机的所有配置文件
include /usr/local/etc/nginx/vhosts/*;
}
5、重新启动 Nginx
systemctl restart nginx