虚拟主机
一台服务器上启动多个网址,每个网址就是一个虚拟主机
虚拟主机可以通过端口,域名区分
一。通过配置不同的端口号区分不同虚拟主机
nginx的配置文件在/usr/local/nginx/conf/路径下的nginx.conf
[root@CentOS6 ~]# cd /usr/local/nginx/conf/
[root@CentOS6 conf]# ll
总用量 60
-rw-r--r--. 1 root root 1034 7月 24 17:06 fastcgi.conf
-rw-r--r--. 1 root root 1034 7月 24 17:06 fastcgi.conf.default
-rw-r--r--. 1 root root 964 7月 24 17:06 fastcgi_params
-rw-r--r--. 1 root root 964 7月 24 17:06 fastcgi_params.default
-rw-r--r--. 1 root root 2837 7月 24 17:06 koi-utf
-rw-r--r--. 1 root root 2223 7月 24 17:06 koi-win
-rw-r--r--. 1 root root 3957 7月 24 17:06 mime.types
-rw-r--r--. 1 root root 3957 7月 24 17:06 mime.types.default
-rw-r--r--. 1 root root 1958 7月 24 18:04 nginx.conf
-rw-r--r--. 1 root root 2656 7月 24 17:06 nginx.conf.default
-rw-r--r--. 1 root root 596 7月 24 17:06 scgi_params
-rw-r--r--. 1 root root 596 7月 24 17:06 scgi_params.default
-rw-r--r--. 1 root root 623 7月 24 17:06 uwsgi_params
-rw-r--r--. 1 root root 623 7月 24 17:06 uwsgi_params.default
-rw-r--r--. 1 root root 3610 7月 24 17:06 win-utf
[root@CentOS6 conf]#
通过不同的域名区分虚拟主机
一个域名对应一个ip地址,一个ip地址可以被多个域名绑定。正常情况下通过DNS服务器解析浏览器输入的域名来解析成IP地址
本地测试可以修改hosts文件。
修改window的hosts文件:(C:\Windows\System32\drivers\etc)
可以配置域名和ip的映射关系,如果hosts文件中配置了域名和ip的对应关系,不需要走dns服务器。
使用switchHost指定域名和IP映射关系
修改config文件
./nginx -s reload重启服务