Nginx基于主机方式配置虚拟主机



vim /etc/host

192.168.237.128 1.qwesky.com

192.168.237.128 2.qwesky.com


在/etc/nginx/conf.d目录下创建

文件default.conf



server {
listen 80;
server_name 1.qwesky.com;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

}



文件default2.conf


server {
listen 80;
server_name 2.qwesky.com;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

测试:

http://1.qwesky.com

http://2.qwesky.com



test2026-06-10 22:56