阿里云linux配置基于名称的虚拟主机

时间:2022-08-01 12:06:06

  公司用的是阿里云的云服务器ECS,本来线上有一个商城,然后又开发了一个项目,刚起步,流量不大,然后我建议依然用我们阿里云的服务器,基于名称,即一个IP上面搭建多个网站,以前也没真正动手配置过,只在本地配置过虚拟主机 ,感觉原理都一样,然后中间出了一些问题吧,本来是打算用wdcp控制面板的,但是不知道什么原因,没有安装成功,然后就连ftp动手配置,中间出现了403,没有权限访问服务器,然后就把根目录下的项目权限改成了777,但是一直还是禁止访问,后来在一篇博客里面看到了Apache虚拟主机的文档,http://httpd.apache.org/docs/2.4/vhosts/   然后删了原来的配置,从新开始,首先在httpd.conf里加入如下代码

<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com
DocumentRoot "/www/domain"
</VirtualHost>

<VirtualHost *:80>
ServerName other.example.com
DocumentRoot "/www/otherdomain"
</VirtualHost>
  接着就在httpd-vhosts.conf进行常规配置,记得根目录末尾不要带 /

<VirtualHost *:80>
    ServerName www.example.cn
    ServerAdmin 2fgrknrng@qq.com
    DocumentRoot /usr/local/www/mulu1
    DirectoryIndex index.php index.html index.htm index.shtml
    CustomLog "logs/dummy-host2.example.com-access_log" common
    Loglevel warn
    HostNameLookups off
    <Directory /usr/local/www/mulu1>
     AllowOverride ALL
     Order allow,deny
     Allow from all
    </Directory>
</VirtualHost>
根目录下放着一个index.html文件,写着 hello,world,配置一天,下班前终于看见了hello,world,激动不已,写下这篇博客,打卡下班