天天看点

AWS (Amazon Web services) 免费主机测试使用流程 --- 一机绑定多域名

Amazon 能免费给用一年的主机,那当然物尽其用啦。

因为AWS EC2 提供的应该就是 Xen 的虚拟主机,就可以当作一台真正的远程主机进行所以你在本地机器可以使用的操作啦。

那你就不仅仅是用来×××了吧。想×××点击这里。

同样,我们可以利用其来搭建属于自己的网站,并支持绑定域名哦,呵呵。

在Linux底下安装好LAMP,并绑定好域名,都是非常简单的几个指令和在域名商那添加一下A记录就可以的了。

但如果你有多个域名呢?空间已经有免费的给你了,而且速度也是飞快的,现在物价上涨那么快,能节省点开支就省点吧。怎么省呢,那当然最好是几个域名都能同时使用到AWS 的主机空间,并且互不干扰啦。

有 心的同学已经发觉到,其实主机都是自己控制的了,那想怎么配置就是自己的事了,和是不是 AWS 其实没什么关系。在google 上一搜‘apache multiple domains’ 就有一大堆教程了,不过我还是想将其写下来。你看到这里就可以了,以下纯属个人为了留个记录而已。

************************   Ubuntu ************************************

参照  Hosting multiple websites with Apache2  http://www.debian-administration.org/articles/412

先在 /var/www/ 下新建好不同的文件夹对于不同的域名,如

mkdir example1.com

mkdir example2.com

再到 /etc/apache2/conf.d/ 配置文件夹底下新建 virtual.conf

vim virtual.conf

写入,保存

NameVirtualHost *

在返回一级,看到有 sites-available,sites-enabled 两文件夹,从名字我们就大概可以判断出:

sites-available 存放的就是配置好的信息,但未激活使用

sites-enabled  但配置信息激活了,就会copy一份到这边来,apache 就能根据这里的配置去区分不同的域名所要响应的文件夹了

配置信息可以这样些

vim example1.com

<VirtualHost *>

        ServerAdmin [email protected]

        ServerName  www.example1.com

        ServerAlias example1.com

        # Indexes + Directory Root.

        DirectoryIndex index.html

        DocumentRoot /home/www/www.example1.com/htdocs/   //根目录

        # CGI Directory

        ScriptAlias /cgi-bin/ /home/www/www.example1.com/cgi-bin/

        <Location /cgi-bin>

                Options +ExecCGI

        </Location>

        # Logfiles

        ErrorLog  /home/www/www.example1.com/logs/error.log  // 自定义位置

        CustomLog /home/www/www.example1.com/logs/access.log combined  //自定义位置

</VirtualHost>

另一个

vim example2.com

        ServerAdmin [email protected]

        ServerName  www.example2.com

        ServerAlias example2.com

        DocumentRoot /home/www/www.example2.com/htdocs/   //根目录

        ScriptAlias /cgi-bin/ /home/www/www.example2.com/cgi-bin/

        ErrorLog  /home/www/www.example2.com/logs/error.log  // 自定义位置

        CustomLog /home/www/www.example2.com/logs/access.log combined // 自定义位置

配置信息写好了,接下来激活就可以使用了。再这里,apache 有新的用法,更方便的管理虚拟主机

a2ensite example1.com example2.com

/etc/init.d/apache2 reload

这样就可以了。

PS: Ubuntu 里的 Apache有四个新的命令 a2enmod ,a2ensite, a2dismod,a2dissite,a2enmod 和 a2dismod分别是激活和去除 模块的,a2ensite 和 a2dissite 自然也就是激活和去除 配置信息的啦。

********************************************* CentOS **********************************************

Redhat系列,如CentOS就更为简单啦

Apache2 配置文件位于  /etc/httpd/conf/httpd.conf

打开拉到最后,去掉 NameVirtualHost *:80 前的 #

然后按照给的例子配置虚拟主机

还有,相应的域名直接绑定到 AWS 的主机 IP 就可以了。

继续阅读