Nginx虚拟主机[多域名、多端口]
分别写入配置 ,基于域名的虚拟主机,这样写 域名1:dnf.com [root@web /etc/nginx/conf.d]#touch dnf.conf server { listen 80; server_name dnf.com; # 这里写的是域名 charset utf-8; location / { root /www/dnf/; # 根目录dnf index index.html; } } 域名2:lol.com [root@web /etc/nginx/conf.d]#touch lol.conf server { listen 80; server_name lol.com; # 这里写的是域名 charset utf-8; location / { root /www/lol/; # 根目录lol index index.html; } }
#然后重启nginx生效
[root@web /etc/nginx/conf.d]#systemctl restart nginx
vim /etc/nginx/conf.d/port.conf # 平级 server { listen 10.0.0.8:81; #这里写ip:端口 server_name _; #_代表空 charset utf-8; location / { root /www/data81/; index index.html; } } # 平级 server { listen 10.0.0.8:82;#这里写ip:端口 server_name _; #_代表空 charset utf-8; location / { root /www/data82/; index index.html; } }
#然后重启nginx生效
[root@web /etc/nginx/conf.d]#systemctl restart nginx