11、nginx配置虚拟主机机
1.配置文件
# 设置进程数
worker_processes 4;
# 设置启动用户,一般情况下设置为当前用户,要不然会出现权限不足
user root;
events {
worker_connections 1024;
}
http {
# 设置虚拟主机1
server {
listen 8001;
server_name 172.16.122.177;
access_log /root/nginx/server/data0/access.log;
error_log /root/nginx/server/data0/error.log;
location / {
root /root/nginx/server/data0;
index index.html index.htm;
}
}
# 设置虚拟主机2
server {
listen 8002;
server_name 172.16.122.177;
access_log /root/nginx/server/data1/access.log;
error_log /root/nginx/server/data1/error.log;
location / {
root /root/nginx/server/data1;
index index.html index.htm;
}
}
# 设置虚拟主机3
server {
listen 8003;
server_name 172.16.122.177;
access_log /root/nginx/server/data2/access.log;
error_log /root/nginx/server/data2/error.log;
location / {
root /root/nginx/server/data2;
index index.html index.htm;
}
}
# 基于域名的虚拟主机
server {
listen 8004;
server_name aaa.domain.com;
access_log /root/nginx/server/data3/access.log;
error_log /root/nginx/server/data3/error.log;
location / {
root /root/nginx/server/data3;
index index.html index.htm;
}
}
server {
listen 8004;
server_name bbb.domain.com;
access_log /root/nginx/server/data4/access.log;
error_log /root/nginx/server/data4/error.log;
location / {
root /root/nginx/server/data4;
index index.html index.htm;
}
}
}
修改hosts文件的域名映射

请求头

2.启动nginx
nginx -s stop && nginx -c nginx_virtual_hosts.conf

3.访问页面
8001 端口

8002端口

8003端口

aaa.domain.com:8004

bbb.domain.com:8004

浙公网安备 33010602011771号