Nginx的虚拟主机配置步骤
![](https://img.haomeiwen.com/i11016594/19ff626d2dd93d4b.png)
第一步:ip地址的配置
使用ifconfig命名进行IP地址的配置
ifconfig eth0 192.168.1.9 netmask 255.255.255.0
进行子设备ip地址设置
ifconfig eth0:1 192.168.1.7 broadcast 192.168.1.255 netmask 255.255.255.0
ifconfig eth0:2 192.168.1.17 broadcast 192.168.1.255 netmask 255.255.255.0
第二步:Nginx的虚拟主机的配置
1 cd /usr/local/nginx/conf
2 touch xunizhuji.conf
3 vim xunizhuji.conf
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 192.168.1.7:80;
server_name 192.168.1.7;
# combined 为日志文件的格式,下一篇会讲
access_log logs/server1.access.log combined;
location /
{
# index指的是索引文件
index index.html index.htm;
# root指的是nginx的安装目录
root html/server1;
}
}
server {
listen 192.168.1.17:80;
server_name 192.168.1.17;
access_log logs/server2.access.log combined;
location / {
index index.html index.htm;
root html/server2;
}
}
}
4 启动nginx
nginx -c conf/xunizhuji.conf
5访问网站
![](https://img.haomeiwen.com/i11016594/71ea86e2b23c2cb2.png)
![](https://img.haomeiwen.com/i11016594/42083f0c06559a6b.png)
注意:直接访问IP地址,会返回index后指定的默认页面
如果要访问index或其他文件,可以在IP地址后面加上文件名
网友评论