在我的本地网络中,我有一个ubuntu服务器(可以通过http:// server到达它)我已经准备好了所有灯,并建立了两个网站,当我在使用时可以访问这些网站。服务器本身,方法如下:
http://localhost.test1.com和http://localhost.test2.com
在主机上,我想通过编辑主机文件将这些URL转发到服务器来访问这些站点。
server localhost.test1.com
server localhost.test2.com
这会将我的请求发送到服务器,但是服务器仅提供默认网站。
我想念什么?如何强迫apache知道我要前往哪个网站?
您需要在apache的配置中为每个站点设置一个虚拟服务器/etc/apache2/sites-available
。您可以通过为每台服务器创建一个新的文件conf文件来做到这一点,我只需要复制默认配置即可。然后,在每个文件中,您需要在文件开头进行修改。
默认文件:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
您将需要分别更改虚拟主机信息和documentRoot。
例子
<VirtualHost localhost.test1.com:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/foo/test1
最后,您需要启用这些新网站
sudo a2ensite test1
注意:站点名称基于conf文件的名称。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句