You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:如何在Amazon AWS Cloud9环境中创建可访问的子域名

Setting Up a Subdomain in AWS Cloud9 with Apache

Hey there! I get that setting up a subdomain in Cloud9 feels a bit different from EC2—let's break this down simply, since Cloud9's domain is managed directly by AWS and we can't adjust its DNS records like we would with a regular EC2 instance. Here's how to make your subdomain work:

Step 1: Understand the Cloud9 Domain Quirk

Unlike EC2 where you can control DNS via Route53 or your own registrar, Cloud9's assigned domain (like xxxxxxxxxxxxxxxx.vfs.cloud9.eu-west-1.amazonaws.com) is locked down. We can't create actual DNS subdomains for it, but we can use Apache's virtual hosts to route requests based on the Host header in the HTTP request. That's how we'll mimic a subdomain setup.

Step 2: Create a New Virtual Host Configuration

First, let's set up a separate virtual host for your subdomain:

  1. Create a directory for your subdomain's content (replace subdomain with your desired name):
    sudo mkdir /var/www/subdomain
    sudo chown -R $USER:$USER /var/www/subdomain
    
  2. Add a test HTML file to verify later:
    echo "<h1>Hello from subdomain!</h1>" > /var/www/subdomain/index.html
    
  3. Create a new Apache site configuration file. Let's call it subdomain.conf:
    sudo nano /etc/apache2/sites-available/subdomain.conf
    
  4. Paste this configuration into the file, replacing the ServerName with your full subdomain URL:
    <VirtualHost *:8080>
        ServerAdmin webmaster@localhost
        ServerName subdomain.xxxxxxxxxxxxxxxx.vfs.cloud9.eu-west-1.amazonaws.com
        DocumentRoot /var/www/subdomain
    
        ErrorLog ${APACHE_LOG_DIR}/subdomain-error.log
        CustomLog ${APACHE_LOG_DIR}/subdomain-access.log combined
    </VirtualHost>
    

Step 3: Enable the New Site and Restart Apache

  1. Enable the new virtual host:
    sudo a2ensite subdomain.conf
    
  2. Restart Apache to apply changes:
    sudo systemctl restart apache2
    

Step 4: Verify Your Setup

Now try accessing subdomain.xxxxxxxxxxxxxxxx.vfs.cloud9.eu-west-1.amazonaws.com in your browser. You should see the test "Hello from subdomain!" message.

Why the EC2 Tutorial Didn't Work

EC2 tutorials usually focus on configuring DNS records (like in Route53) to point a subdomain to your instance's IP. But Cloud9 doesn't let you modify its domain's DNS—instead, we rely on Apache to look at the incoming request's Host header and route it to the correct directory. That's the key difference here!

内容的提问来源于stack exchange,提问作者Fifi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 14:47:29