【问题标题】:Service for Ubuntu server to make multiple Website [closed]为 Ubuntu 服务器创建多个网站的服务 [关闭]
【发布时间】:2023-04-04 13:28:01
【问题描述】:

我有一个 Ubuntu 12.04 LTS 服务器 VPS,我想制作一个 Web 服务器来存储多个网站(托管)。

请给我一些服务。

  • LAMP、mysql、phpMyadmin
  • Webmin

还有什么?

(仅适用于 Web 服务器,不适用于应用程序)

【问题讨论】:

    标签: ubuntu ubuntu-12.04 vps


    【解决方案1】:

    在此处查看文章:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts 请注意,这不仅适用于 Ubuntu,它应该适用于任何其他 Linux 发行版,也可能适用于 Unix 和 Mac

    假设您希望在单个服务器上拥有 example.com 和 test.com。

    首先你制作这样的文件结构。您需要在 /var/www/ 中为每个网站创建一个目录,并且在每个网站中,您都需要一个 public_html 文件夹。所以你的目录应该是这样的: /var/www/example.com/public_html/ /var/www/test.com/public_html/

    然后您需要授予普通用户编辑这些文件夹的权限,以及其他所有人查看它们的权限,所以在终端中运行:

    sudo chown -R $USER:$USER /var/www/example.com/public_html 
    sudo chown -R $USER:$USER /var/www/test.com/public_html
    sudo chmod -R 755 /var/www
    

    现在您应该将 index.html 文件放入每个 public_html 目录中,并在其中放入一些内容,以便您测试它是否正常工作。

    然后您需要在 /etc/apache2/sites-available/example.com.conf 中创建一个虚拟主机文件。这就是 example.com 的样子。然后你为 test.com 制作另一个并复制它,只需将“example.com”更改为“test.com”。

    <VirtualHost *:80> 
        ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com/public_html 
        ErrorLog ${APACHE_LOG_DIR}/error.log 
        CustomLog ${APACHE_LOG_DIR}/access.log combined 
    </VirtualHost>
    

    完成后,您需要启用这些虚拟主机文件。为此,您必须在终端中运行以下命令。

    sudo a2ensite example.com.conf
    sudo a2ensite test.com.conf
    sudo service apache2 restart
    

    您很可能会收到类似以下内容的消息:

    * Restarting web server apache2 AH00558: apache2: 
    Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. 
    Set the 'ServerName' directive globally to suppress this message 
    

    这是一条无害的信息,不会影响我们的网站。

    如果您没有使用自己拥有的实际域名来测试此过程,而是使用了一些示例域,您至少可以通过临时修改本地计算机上的 hosts 文件来测试此过程的功能。

    假设 VPS IP 地址是 111.111.111.111,您可以在 hosts 文件底部添加以下行:

    111.111.111.111 example.com
    111.111.111.111 test.com 
    

    这会将任何对 example.com 和 test.com 的请求定向到我们的计算机上,并将它们发送到我们的服务器 111.111.111.111。如果我们实际上不是这些域的​​所有者,那么这就是我们想要的,以便测试我们的虚拟主机。

    保存并关闭文件。

    现在您可以测试您的结果了。如果您访问 example.com 或 test.com,您应该会看到您之前创建的 index.html 文件。

    【讨论】:

      猜你喜欢
      • 2012-08-02
      • 2014-03-21
      • 1970-01-01
      • 2022-09-24
      • 1970-01-01
      • 2010-09-21
      • 2010-09-24
      • 1970-01-01
      • 2012-07-12
      相关资源
      最近更新 更多