如何在Centos Apache上使用不同端口在同一域上运行两个网站

时间:2018-09-12 14:43:56

标签: apache centos7 virtualhost

我已经有一个在端口443上运行的网站。我在Apache上使用CentOS 7环境。

因此,域为:https://www.example.com

现在,我还有一个网站,并希望在同一个端口(例如444)上运行该网站。因此,该网站的最终网址应为:

http://www.example.com:444

要在端口443上运行第一个网站,我已经做了以下事情:

步骤1:在“ /etc/httpd/sites-available/website1.conf”中创建了一个conf文件。该文件包含以下代码:

<VirtualHost *:443> 
      ServerName server-ip 
      ServerAlias server-ip 
      DocumentRoot "/opt/lampp/htdocs/website1/" 
      DirectoryIndex index.html index.php 
     <Directory "/opt/lampp/htdocs/live/"> 
       Options Indexes FollowSymLinks Includes ExecCGI 
       DirectoryIndex index.php index.html 
       AllowOverride All
       Order allow,deny 
       Allow from all 
     </Directory> 
</VirtualHost>  

步骤2:启用此虚拟主机文件,以便Apache可以了解此虚拟主机。

步骤3:转到主机文件“ / etc / host”,并针对提到的server-ip对该虚拟主机进行输入:
    my-server-ip www.example.com

因此,以上所有内容均正常运行,并且我的网站在网域www.example.com上运行。

现在,我创建了另一个具有相同域名但具有不同端口号的虚拟主机,如下所示:

步骤1:在“ /etc/httpd/sites-available/website2.conf”下创建了.conf文件。该文件包含以下代码:

<VirtualHost *:444> 
      ServerName same-server-ip 
      ServerAlias same-server-ip 
      DocumentRoot "/opt/lampp/htdocs/website2/" 
      DirectoryIndex index.html index.php 
     <Directory "/opt/lampp/htdocs/live/"> 
       Options Indexes FollowSymLinks Includes ExecCGI 
       DirectoryIndex index.php index.html 
       AllowOverride All
       Order allow,deny 
       Allow from all 
     </Directory> 
</VirtualHost>  

步骤2:启用了这个新网站。

第3步:在/etc/http/conf/httpd.conf的.conf文件中此端口的下面添加了此端口号:

Listen 80  
Listen 444  

步骤4:之后,重新启动Apache。

现在,当我点击URL:www.example.com:444时,服务器将我重定向到第一个网站www.example.com。

我无法弄清我错过了什么。有人可以帮我吗?

0 个答案:

没有答案