<h2 id="实验环境">实验环境
- 一台最小化安装的CentOS 7.3虚拟机
yum install -y epel-*
yum isntall -y nginx vim
mkdir /var/wwwroot
mkdir /var/wwwroot/site1
mkdir /var/wwwroot/site2
echo -e "site1" >> /var/wwwroot/site1/index.html
echo -e "site2" >> /var/wwwroot/site2/index.html
yum install -y epel-* yum isntall -y nginx vim
mkdir /var/wwwroot
mkdir /var/wwwroot/site1
mkdir /var/wwwroot/site2
echo -e "site1" >> /var/wwwroot/site1/index.html
echo -e "site2" >> /var/wwwroot/site2/index.html
setenforce 0
systemctl stop firewalld
systemctl disable firewalld
vim /etc/nginx/conf.d/vhosts.conf
server {
listen 8081;
root /var/wwwroot/site1;
index index.html;
location / {
}
}
server {
listen 8082;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
vim /etc/nginx/conf.d/vhosts.conf
server {
listen 8081;
root /var/wwwroot/site1;
index index.html;
location / {
}
}
server {
listen 8082;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
location / {
}
}
server {
listen 8082;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
nginx服务
systemctl start nginx
http://192.168.204.135:8081/
http://192.168.204.135:8082/
vim /etc/nginx/conf.d/vhosts.conf
server {
listen 80;
server_name site1.test.com;
root /var/wwwroot/site1;
index index.html;
location / {
}
}
server {
listen 80;
server_name site2.test.com;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
vim /etc/nginx/conf.d/vhosts.conf
server {
listen 80;
server_name site1.test.com;
root /var/wwwroot/site1;
index index.html;
location / {
}
}
server {
listen 80;
server_name site2.test.com;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
location / {
}
}
server {
listen 80;
server_name site2.test.com;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
nginx服务
systemctl restart nginx
hosts文件
编辑C:\Windows\System32\drivers\etc\hosts
文件,
添加以下内容(根据实际情况自己修改)
192.168.204.135 site1.test.com 192.168.204.135 site2.test.com
http://site1.test.com/
http://site2.test.com/
ifconfig ens33:1 192.168.204.151
ifconfig ens33:2 192.168.204.152
vim /etc/nginx/conf.d/vhosts.conf
server {
listen 192.168.204.151:80;
root /var/wwwroot/site1;
index index.html;
location / {
}
}
server {
listen 192.168.204.152:80;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
ifconfig ens33:1 192.168.204.151 ifconfig ens33:2 192.168.204.152
vim /etc/nginx/conf.d/vhosts.conf
server {
listen 192.168.204.151:80;
root /var/wwwroot/site1;
index index.html;
location / {
}
}
server {
listen 192.168.204.152:80;
root /var/wwwroot/site2;
index index.html;
location / {
}
}
server { listen 192.168.204.151:80; root /var/wwwroot/site1; index index.html;location / { }
}
server {
listen 192.168.204.152:80;
root /var/wwwroot/site2;
index index.html;location / {
}
}
nginx服务
systemctl restart nginx
http://192.168.204.151/
http://192.168.204.152/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。