1.配置虚拟主机
vi /etc/hosts
进行添加网址
2.配置nginx.conf
[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
include vhost/*.conf; #vhost目录下会包含所有的虚拟主机的配置文件 接上ServerRoot路径
}
3.配置*.conf
[root@localhost conf]mkdir /usr/local/nginx/conf/vhost
[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/www.1.com.conf
server{
listen 80;
server_name 1.com www.1.com;
index index.html;
root /data/wwwroot/www.1.com;
}
[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/www.2.com.conf
server{
listen 80;
server_name 2.com www.2.com;
index index.html;
root /data/wwwroot/www.2.com;
}
4.重启测试
[root@localhost root]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5.只是修改时候可以选择重新加载
当配置文件修改时,可以使用一下命令重新加载配置文件
[root@localhost sbin]# ./nginx -s reload
6.浏览器访问
linux内部curl访问
windows浏览器访问
如果linux可以 windows不可以 可以相互ping通
就是防火墙的问题