I have a Linux web server with Apache (httpd). How to host multiple websites on Apache?
我有一个带有Apache( httpd )的Linux Web服务器。 如何在Apache上托管多个网站?
To host websites www.example1.com and www.example2.com on a single node with Apache2 on a single IP, you can use VirtualHost as follows.
要将网站www.example1.com和www.example2.com托管在单个节点上,而Apache2托管在单个IP上,则可以按以下方式使用VirtualHost。
Edit /etc/httpd/conf/httpd.conf
and add the following lines:
编辑/etc/httpd/conf/httpd.conf
并添加以下行:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/example1.com
ServerName www.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example2.com
ServerName www.example2.com
# Other directives here
</VirtualHost>
Then you can store your websites under the corresponding directory specified with DocumentRoot for each domain.
然后,您可以将网站存储在每个域的DocumentRoot指定的相应目录下。
After restarting Apache2 by # apachectl restart
or # systemctl restart httpd.service
or # service httpd restart
or other distro specific commands, each domain (point to the web server) will be in each own’s directory.
通过# systemctl restart httpd.service
# apachectl restart
或# systemctl restart httpd.service
或# systemctl restart httpd.service
# service httpd restart
或其他发行版特定命令来重启Apache2之后,每个域( 指向 Web服务器)将位于各自的目录中。
Note that www.example1.com and example1.com are two different domains and you will need to set up two virtual hosts if you want to use both.
请注意,www.example1.com和example1.com是两个不同的域,如果要同时使用两个,则需要设置两个虚拟主机。
翻译自: https://www.systutorials.com/how-to-host-multiple-websites-on-a-apache-linux-web-server/