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

已在Route53创建绑定EC2的blog子域名,如何部署网站?

Hey there! Let's get your blog subdomain fully set up with your custom website—here's a step-by-step breakdown tailored to your Amazon Linux AMI setup:

1. Confirm Your Web Server is Running

First, since you're seeing the Amazon Linux test page, your web server (most likely Apache, the default for Amazon Linux) is already active. To double-check, run this command via SSH:

sudo systemctl status httpd

If it's not running, start it with sudo systemctl start httpd and enable auto-start on boot: sudo systemctl enable httpd.

2. Create a Directory for Your Subdomain's Files

Subdomain directories aren't auto-generated—you'll need to create one manually. A clean, organized approach is to use a structure tied directly to your subdomain:

  • Create the root directory and a public_html folder (where your actual website files will live):
    sudo mkdir -p /var/www/blog.domain.com/public_html
    
  • Set proper permissions so your web server can access the files:
    sudo chown -R apache:apache /var/www/blog.domain.com/public_html
    sudo chmod -R 755 /var/www
    

This ensures the Apache user (the process running your web server) can read and serve your files without permission issues.

3. Configure Virtual Hosts to Map the Subdomain to Your Directory

Virtual hosts let your web server know which files to serve when someone visits blog.domain.com. Here's how to set it up for Apache:

  1. Create a new configuration file in Apache's conf.d directory:
    sudo nano /etc/httpd/conf.d/blog.conf
    
  2. Paste in this configuration (adjust ServerAlias if you want to include www.blog.domain.com):
    <VirtualHost *:80>
        ServerName blog.domain.com
        ServerAlias www.blog.domain.com
        DocumentRoot /var/www/blog.domain.com/public_html
        ErrorLog /var/log/httpd/blog-error.log
        CustomLog /var/log/httpd/blog-access.log combined
    </VirtualHost>
    
  3. Save and exit (in nano, press Ctrl+O, then Enter, then Ctrl+X).
  4. Test the configuration for syntax errors:
    sudo apachectl configtest
    
    If you see Syntax OK, restart Apache to apply changes:
    sudo systemctl restart httpd
    

If You're Using Nginx Instead (Optional)

If you switched to Nginx, the process is similar:

  1. Create the same directory structure as above.
  2. Create a Nginx config file:
    sudo nano /etc/nginx/conf.d/blog.conf
    
  3. Paste this configuration:
    server {
        listen 80;
        server_name blog.domain.com;
        root /var/www/blog.domain.com/public_html;
        index index.html index.htm;
        access_log /var/log/nginx/blog-access.log;
        error_log /var/log/nginx/blog-error.log;
    
        location / {
            try_files $uri $uri/ =404;
        }
    }
    
  4. Test and restart Nginx:
    sudo nginx -t
    sudo systemctl restart nginx
    
4. Upload Your Blog Files

Now, use WinSCP to upload all your blog website files (HTML, CSS, JS, images, etc.) directly to the /var/www/blog.domain.com/public_html/ directory. Replace any default files here (if there are any) with your own content.

5. Test Your Subdomain

Visit blog.domain.com in your browser—you should now see your custom blog instead of the Amazon Linux test page! If you run into issues, check the log files we configured (e.g., /var/log/httpd/blog-error.log) to troubleshoot permission problems or config mistakes.

内容的提问来源于stack exchange,提问作者Vino G. Baskoro

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:46:24