在 Amazon EC2 中创建子域 [英] Creating subdomains in Amazon EC2

查看:25
本文介绍了在 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:

  1. 购买域名.如果您有,请跳过此部分,我们将以 example.com 为例.
  2. 查找您的 EC2 实例的外部 IP 或 DNS.您可能希望将弹性 IP 与您的实例相关联,否则您的实例的 IP 会在重启时发生变化.
  3. 为您的域创建 DNS 记录,例如指向您的弹性 IP/DNS 名称的 CNAME 记录:

  1. Purchase a domain. If you have one, skip this, we'll take example.com for this example.
  2. 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.
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆