Linux 在 Amazon EC2 中创建子域

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4203580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:00:40  来源:igfitidea点击:

Creating subdomains in Amazon EC2

linuxamazon-ec2subdomain

提问by Padmanabha Vn

How can I create subdomains on Amazon EC2?

如何在 Amazon EC2 上创建子域?

Is adding virtual host in httpd.conf is enough.. or any other changes also needs to be done?

在 httpd.conf 中添加虚拟主机就足够了.. 或者还需要做任何其他更改吗?

Thanks

谢谢

采纳答案by cvaldemar

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:

取决于您的服务器软件。但是正如您提到的 httpd.conf,您很有可能在 Linux 发行版上运行 Apache。如果是这种情况,那么是的,添加一个虚拟主机就足够了。这是一种方法:

  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

  4. Make sure your httpd.conf contains a line to allow virtual hosts:

    NameVirtualHost *:80

  5. Create a virtual host directive:

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

    subdomain.example.com => ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com

  4. 确保您的 httpd.conf 包含一行以允许虚拟主机:

    NameVirtualHost *:80

  5. 创建一个虚拟主机指令:

httpd.conf:

httpd.conf:

<VirtualHost *:80>
  ServerName subdomain.example.com
  ServerAdmin [email protected]

  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. Restart Apache

6.重启Apache

/etc/init.d/apache2 restart