如何在Apache Linux Web服务器上托管多个网站?

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是两个不同的域,如果要同时使用两个,则需要设置两个虚拟主机。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-host-multiple-websites-on-a-apache-linux-web-server/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值