1.虚拟主机的三种类型
基于域名的虚拟主机、基于端口的虚拟主机、基于ip的虚拟主机
2.基于域名的虚拟主机配置
[root@CentOS7 conf]# egrep -v "#|^$" nginx.conf.default > nginx.conf
[root@CentOS7 conf]# vim nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.test.com;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@CentOS7 conf]# mkdir ../html/www
[root@CentOS7 conf]# echo "www.test.com" > ../html/www/index.html
[root@CentOS7 conf]# ../sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.16.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.16.1/conf/nginx.conf test is successful
[root@CentOS7 conf]# ../sbin/nginx -s reload
[root@CentOS7 conf]# echo "192.168.244.130 www.test.com" >> /etc/hosts #增加hosts解析
[root@CentOS7 conf]# tail -1 /etc/hosts
192.168.244.130 www.test.com
[root@CentOS7 conf]# curl www.test.com
www.test.com #index.html内容访问正常
3.配置多个虚拟主机
在http区块内,增加server区块即可。
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.test.com;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.test1.com;
location / {
root html/www1;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
「 文章如果对你有帮助,请点个赞哦^^ 」 
0
若无特殊注明,文章均为本站原创或整理发布。
转载请注明本文地址:https://om.fangxiaoxiong.com/1635.html