Apache和Nginx虚拟主机的创建
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Apache和Nginx虚拟主机的创建,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2375字,纯文字阅读大概需要4分钟。
内容图文
![Apache和Nginx虚拟主机的创建](/upload/InfoBanner/zyjiaocheng/949/510e7cd5fc774681952d315c7bdd4a41.jpg)
一、Apache
(1)基于访问主机头(FQDN)
cat /etc/httpd/conf.d/vhostfqdn.conf <virtualhost *:80> documentroot /data/web01 servername www.web01.com <directory /data/web01> require all granted </directory> CustomLog "logs/a_access_log" combined </virtualhost> <virtualhost *:80> documentroot /data/web02 servername www.web02.com <directory /data/web02> require all granted </directory> CustomLog "logs/a_access_log" combined </virtualhost> <virtualhost *:80> documentroot /data/web03 servername www.web03.com <directory /data/web03> require all granted </directory> CustomLog "logs/a_access_log" combined </virtualhost>
(2)基于ip地址
cat /etc/httpd/conf.d/vhostip.conf <virtualhost 192.168.130.11:80> documentroot /data/web01 <directory /data/web01> require all granted </directory> </virtualhost> <virtualhost 192.168.130.22:80> documentroot /data/web02 <directory /data/web02> require all granted </directory> </virtualhost> <virtualhost 192.168.130.33:80> documentroot /data/web03 <directory /data/web03> require all granted </directory> </virtualhost>
(3)基于端口号
cat /etc/httpd/conf.d/vhostport.conf listen 8001 listen 8002 listen 8003 <virtualhost *:8001> documentroot /data/web01 <directory /data/web01> require all granted </directory> </virtualhost> <virtualhost *:8002> documentroot /data/web02 <directory /data/web02> require all granted </directory> </virtualhost> <virtualhost *:8003> documentroot /data/web03 <directory /data/web03> require all granted </directory> </virtualhost>
二、Nginx
(1)基于域名且不同站点
server { listen 80; server_name mobile.magedu.com; location / { root html; index index.html index.htm; } location /python { root /mobile; !!!必须在/mobile目录下创建/python目录,且把文件写入python目录中,否则会报错!!! index index.html index.htm; } location /java { root /mobile; index index.html index.htm; } } server { listen 80; server_name www.magedu.com; location / { root html; index index.html index.htm; } location /python { root /www; index index.html index.htm; } location /java { root /www; index index.html index.htm; } }
内容总结
以上是互联网集市为您收集整理的Apache和Nginx虚拟主机的创建全部内容,希望文章能够帮你解决Apache和Nginx虚拟主机的创建所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。