大佬教程收集整理的这篇文章主要介绍了配置Nginx虚拟主机,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<h2 id="实验环境">实验环境
yum install -y epel-* yum isntall -y nginx vim
@mkdir /var/wwwroot mkdir /var/wwwroot/site1 mkdir /var/wwwroot/site2 echo -e "site1" >> /var/wwwroot/site1/index.html echo -e "site2" >> /var/wwwroot/site2/index.html
title="配置Nginx虚拟主机" alt="配置Nginx虚拟主机" src="https://cn.js-code.com/res/2019/01-27/18/269b3a6ae5118040f4165652054dce98.png">
setenforce 0 systemctl stop firewalld systemctl disable firewalld
title="配置Nginx虚拟主机" alt="配置Nginx虚拟主机" src="https://cn.js-code.com/res/2019/01-27/18/93cda4748721729c310ca2b1c1e6cfca.png">
vim /etc/nginx/conf.d/vhosts.conf
server { listen 8081; root /var/wwwroot/site1; index index.html;@R_772_5352@n / { }
}
server {
listen 8082;
root /var/wwwroot/site2;
index index.html;
title="配置Nginx虚拟主机" alt="配置Nginx虚拟主机" src="https://cn.js-code.com/res/2019/01-27/18/65b623151310e9816b2f620d552240d8.png">
systemctl start nginx
http://192.168.204.135:8081/
http://192.168.204.135:8082/
https://cn.js-code.com/res/2019/01-27/18/f1ad632c146e1cac0d4f4bb3f62ae09a.png">https://cn.js-code.com/res/2019/01-27/18/4964eb1e03ac6d9fb3cd27f8fa6d4ae7.png">
vim /etc/nginx/conf.d/vhosts.conf
server { listen 80; server_name site1.test.com; root /var/wwwroot/site1; index index.html;@R_772_5352@n / { }
}
server {
listen 80;
server_name site2.test.com;
root /var/wwwroot/site2;
index index.html;
title="配置Nginx虚拟主机" alt="配置Nginx虚拟主机" src="https://cn.js-code.com/res/2019/01-27/18/1c6cd670feb1a2e5e4be11d06f0587f2.png">
systemctl restart nginx
编辑C:\Windows\System32\drivers\etc\hosts
文件,
添加以下内容(根据实际情况自己修改)
192.168.204.135 site1.test.com 192.168.204.135 site2.test.com
title="配置Nginx虚拟主机" alt="配置Nginx虚拟主机" src="https://cn.js-code.com/res/2019/01-27/18/6cd0444fd870b6d3f25ee4b9d5f3eac2.png">
http://site1.test.com/
http://site2.test.com/
https://cn.js-code.com/res/2019/01-27/18/dd490b6d86552063ceeabab23fe506cf.png">https://cn.js-code.com/res/2019/01-27/18/43a98242b5d206ef134dfbf6a7d87e09.png">
ifconfig ens33:1 192.168.204.151 ifconfig ens33:2 192.168.204.152
vim /etc/nginx/conf.d/vhosts.conf
server { listen 192.168.204.151:80; root /var/wwwroot/site1; index index.html;@R_772_5352@n / { }
}
server {
listen 192.168.204.152:80;
root /var/wwwroot/site2;
index index.html;
title="配置Nginx虚拟主机" alt="配置Nginx虚拟主机" src="https://cn.js-code.com/res/2019/01-27/18/e0e7138d7843a7b5efceaedc7f8c6033.png">
systemctl restart nginx
http://192.168.204.151/
http://192.168.204.152/
https://cn.js-code.com/res/2019/01-27/18/9c2114cb349521d5286f78b6d344fb32.png">https://cn.js-code.com/res/2019/01-27/18/307a469f13d9b70b69d43cd9136d280e.png">
本文链接:https://www.cnblogs.com/connect/p/nginx-vhost.html" class="uri">https://www.cnblogs.com/connect/p/nginx-vhost.html
以上是大佬教程为你收集整理的配置Nginx虚拟主机全部内容,希望文章能够帮你解决配置Nginx虚拟主机所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。