nginx虚拟主机配置 |
您所在的位置:网站首页 › web虚拟主机需要配置的参数 › nginx虚拟主机配置 |
虚拟主机:
1.基于ip地址 IP-based–》一个域名对应一个ip 2.基于域名(name-based) --》所有的域名使用同一个ip --》使用非常多的 1.修改nginx.conf打开nginx域名配置文件存放路径 cd /usr/local/nginx/conf编辑配置文件 [root@localhost conf]#vim nginx.conf 在配置文件里添加2个server块,对应2个不同的域名 --》加到http块 server { listen 80; server_name www.sc.com ; location / { root html/sc.com; ---》需要在html目录下新建sc.com,并且在里面还要新建首页index.html,内容自己定义 index index.html index.htm; } } server { listen 80; server_name www.xxue.com; location / { root html/xxue.com; ---》需要在html目录下新建feng.com,并且在里面还要新建首页index.html,内容自己定义 index index.html index.htm; } } 2.新建存放网页的文件夹和首页 [root@localhost html]# pwd /usr/local/scnginx8/html [root@localhost html]# [root@localhost scnginx8]# tree html/xxue.com/ html/xxue.com/ └── index.html --》内容是xxue.com 0 directories, 1 file [root@localhost scnginx8]# tree html/sc.com/ html/sc.com/ └── index.html --》内容是sc.com 0 directories, 1 file 3.启动nginx [root@localhost scnginx8]# nginx -t nginx: the configuration file /usr/local/scnginx8/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/scnginx8/conf/nginx.conf test is successful [root@localhost scnginx8]# nginx -s reload 4.测试4.1在客户机上需要修改hosts文件,在里面添加 www.sc.com 192.168.66.2 www.xxue.com 192.168.66.24.2 在浏览器里访问域名 http://www.sc.com 或者http://www.xxue.com 会看到不同内容 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |