Nginx学习历程_2_配置Nginx的虚拟主机

来源:互联网 发布:王尼玛删视频 知乎 编辑:程序博客网 时间:2024/05/03 01:01

1.修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@web www]# vim /etc/nginx/nginx.conf
server { 
        listen       80; 
        server_name  www.nginx.com; 
        location / { 
            root   /data/www
            index  index.html index.htm; 
        
    }
    server { 
        listen       80; 
        server_name  www.test.com; 
        location / { 
            root   /data/test
            index  index.html index.htm; 
        
    }

2.提供测试页面

1
2
3
4
[root@web data]# mkdir test 
[root@web data]# cd test/ 
[root@web test]# cat index.html 
<h1>www.test.com</h1>

3.重新加载nginx配置

1
2
3
4
[root@web run]# service nginx reload 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
nginx: configuration file /etc/nginx/nginx.conf test is successful 
重新载入 nginx:                                           [确定]

4.修改测试机的hosts文件

1
2
3
4
Windows 7下路径:C:\Windows\System32\drivers\etc\hosts
增加两行:
192.168.18.201    www.nginx.com 
192.168.18.201    www.test.com
5.测试一下
访问www.nginx.com ,展示/data/www/index.html
访问www.test.com ,展示/data/test/index.html

0 0
原创粉丝点击