一、创建网站目录及文件:
[root@localhost data]# tree /data /data └── wwwroot ├── www.1.com_8080 │ └── index.html └── www.1.com_8081 └── index.html
[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目录下会包含所有的虚拟主机的配置文件 }
三、创建虚拟主机的配置文件目录:
[root@localhost conf]mkdir /usr/local/Nginx/conf/vhost
四、创建虚拟主机配置文件:
[root@localhost Nginx]# vim /usr/local/Nginx/conf/vhost/www.1.com.8080.conf server{ listen 8080; server_name 1.com www.1.com; index index.html; root /data/wwwroot/www.1.com_8080; }
[root@localhost Nginx]# vim /usr/local/Nginx/conf/vhost/www.1.com.8081.conf server{ listen 8081; server_name 1.com www.1.com; index index.html; root /data/wwwroot/www.1.com_8081; }
[root@localhost Nginx]# vim /usr/local/Nginx/conf/vhost/default.conf server{ listen 80 default_server; #使用default_server指定Nginx的默认虚拟主机 deny all; }
若使用其他域名来访问虚拟主机时,会匹配到默认虚拟主机,该配置会拒绝未定义的域名的虚拟主机。若不配置该选项,默认排在最前边的server会成为默认虚拟主机。
五、测试配置文件是否存在问题:
[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
[root@localhost sbin]# ./Nginx -s reload
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。