目标:实现多域名访问服务器
进入到nginx配置文件,修改nginx.conf配置文件
在#gzip on;下删除所有内容,删除完成后加入以下内容,这里只以a b 两个网站为例,如果还有c d 等网站部署方法也一样,只需按照这种格式复制粘贴就好。
server {
listen 80;
server_name www.a.com;
#access_log logs/host.access.log main;
location / {
root html/a;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.b.com;
#access_log logs/host.access.log main;
location / {
root html/b;
index index.html index.htm;
}
}
}
具体注释
添加完成后去创建 a b 两个发布目录,需在默认发布目录下创建/usr/local/nginx/html
进入a发布目录修改网页内容
[root@localhost html]# cd a
[root@localhost a]# vim index.html
进入b发布目录修改网页内容
root@localhost a]# cd …/
[root@localhost html]# cd b
[root@localhost b]# vim index.html
检查服务是否能正常启动
[root@localhost b]# /usr/local/nginx/sbin/nginx -t
启动服务并查看80端口是否被监听到
[root@localhost b]# /usr/local/nginx/sbin/nginx
[root@localhost b]# netstat -nel |grep 80
因为我们域名不是真正的注册域名,所以只能在本地电脑etc文件添加域名解析后才能访问
访问a网页
访问b网页
1、a b 发布目录需要创建在nginx默认的发布目录下面