在 Amazon EC2 中创建子域 [英] Creating subdomains in Amazon EC2
问题描述
如何在 Amazon EC2 上创建子域?
How can I create subdomains on Amazon EC2?
在httpd.conf中添加虚拟主机就足够了..还是还需要做其他任何更改?
Is adding virtual host in httpd.conf is enough.. or any other changes also needs to be done?
谢谢
推荐答案
取决于您的服务器软件.但是正如您提到的 httpd.conf,您很有可能在 Linux 发行版上运行 Apache.如果是这种情况,那么是的,添加一个虚拟主机就足够了.这是一种方法:
Depends on your server software. But as you mention httpd.conf, chances are good that you run Apache on a Linux distribution. If that's the case then yes, adding a virtual host is enough. Here is one way of doing it:
- 购买域名.如果您有,请跳过此部分,我们将以 example.com 为例.
- 查找您的 EC2 实例的外部 IP 或 DNS.您可能希望将弹性 IP 与您的实例相关联,否则您的实例的 IP 会在重启时发生变化.
为您的域创建 DNS 记录,例如指向您的弹性 IP/DNS 名称的 CNAME 记录:
- Purchase a domain. If you have one, skip this, we'll take example.com for this example.
- Find the external IP or DNS for your EC2 instance. You probably want to associate an Elastic IP to your instance, otherwise the IP of your instance will change on reboots.
Create a DNS record for your domain, for instance a CNAME record to point to your Elastic IP/DNS name:
subdomain.example.com =>ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com
确保您的 httpd.conf 包含一行以允许虚拟主机:
Make sure your httpd.conf contains a line to allow virtual hosts:
NameVirtualHost *:80
创建一个虚拟主机指令:
Create a virtual host directive:
httpd.conf:
httpd.conf:
<VirtualHost *:80>
ServerName subdomain.example.com
ServerAdmin webmaster@subdomain.example.com
DocumentRoot /var/www/example.com/subdomain
<Directory /var/www/example.com/subdomain>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/subdomain.example.com.error.log
LogLevel warn
CustomLog /var/log/apache2/subdomain.example.com.access.log combined
</VirtualHost>
6.重启Apache
/etc/init.d/apache2 restart
这篇关于在 Amazon EC2 中创建子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!