我以前使用cPanel,它有一个名为Add on Domains的function,它允许一个web域指向public_html上的一个子文件夹。
我已经切换到一个没有cPanel的Linux服务器,并希望在Apache中做同样的事情。
我将如何做到这一点?
在Apache中,这被称为虚拟主机 。
Apache wesbite有一个我要借用的configuration示例 ,下面。 显然,你想用自己的代替DocumentRoots和ServerNames的例子,并确保你有正确的DNS设置。
# Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/example1 ServerName www.example.com # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /www/example2 ServerName www.example.org # Other directives here </VirtualHost>
你可以通过在httpd.conf或者apache.conf中添加
这里是例子..
# Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/example1 ServerName www.example.com # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /www/example2 ServerName www.example.org # Other directives here </VirtualHost>
首先,你必须在你的VPS上设置LAMP。 LAMP堆栈是一组用于启动和运行Web服务器的开源软件。 首字母缩写代表Linux,Apache,MySQL和PHP。
一旦设置了LAMP,您将不得不设置Apache虚拟主机,以单个IP地址托pipe多个网站。可以添加到VPS的虚拟主机数量没有限制。 下面是关于如何在CentOS 6和Ubuntu 14.04上设置Apache虚拟主机的很好的指南
https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-centos-6