linux - 在 Amazon EC2 中创建子域

标签 linux amazon-ec2 subdomain

如何在 Amazon EC2 上创建子域?

在 httpd.conf 中添加虚拟主机就足够了..还是还需要进行任何其他更改?

谢谢

最佳答案

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

  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:

<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

关于linux - 在 Amazon EC2 中创建子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4203580/

相关文章:

amazon-ec2 - 在云中运行构建

ssl - 子域不适用于 https,但适用于 http

python - 多个子域的 Django 多 session cookie 域

linux - 收到此错误后如何登录 phpMyAdmin... #2003 无法登录 MySQL 服务器

linux - 同一个 ELF 文件中的多个 ISA

linux - usb_modeswitch 卡在手动开关上

wordpress - 仅在 NGINX 中允许通过 IP 白名单访问某些位置

linux - 根据文件名作为日期删除所有超过 30 天的文件

shell - 将脚本作为用户数据传递到 AWS EC2 spot 实例

amazon-web-services - AWS CloudFormation,堆栈更新不会修改我的 EC2 配置