一台服务器,另一台PC上的多个网站

理查德

在我的本地网络中,我有一个ubuntu服务器(可以通过http:// server到达它)我已经准备好了所有灯,并建立了两个网站,当我在使用时可以访问这些网站。服务器本身,方法如下:

http://localhost.test1.comhttp://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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Flask在另一台服务器上时在本地查找db

如何在一台服务器上使用GitLab并将所有存储库存储在另一台服务器上?

htaccess在一台服务器上正常工作,并导致另一台服务器上的重定向循环

如何导入在另一台服务器上创建的状态?

使用位于另一台服务器上的PHP文件

如何从一台服务器上的水壶作业在另一台服务器上运行Shell脚本?

一台服务器上的远程容器正常工作,另一台服务器上的远程容器不工作

SOAP请求在一台服务器上随机失败,但在iOS7上的另一台服务器上工作

将网站移至另一台服务器后,Magento错误

将文件从一台服务器直接移动到另一台服务器,而无需写入PC磁盘

从一台服务器流到另一台服务器

我可以将一台服务器上的stdout传送到另一台服务器上的stdin吗?

Node.js处理另一台服务器上的登录

将Silvertripe网站从一台服务器迁移到另一台服务器

一台服务器上是否存在Java SSLHandshakeException,而另一台服务器上没有?

什么时候将网站删除到另一台服务器?

从一台服务器移到另一台服务器时,WordPress网站重定向错误

URL在Azure网站上重写到另一台服务器

将一台服务器复制到另一台服务器

如何使用ssh从一台服务器上的文件复制文本并追加到另一台服务器上的文件?

网络C#上另一台服务器上的引用路径

另一台服务器上的git分支

在另一台服务器上的Spring Boot外部配置

授予一台服务器上的IIS对另一台服务器上的文件夹的读取访问权限

关于服务器,何时应该将进程移至另一台服务器而不是同一台服务器上?

Ansible 命令触发在另一台服务器上的注册

如何将图像从网站保存到另一台服务器

用于从另一台服务器上的 Elasticsearch 获取数据的 PHP 脚本

Imagick 功能可在一台服务器上运行,但不能在另一台服务器上运行