已在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:
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.
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_htmlfolder (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.
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:
- Create a new configuration file in Apache's conf.d directory:
sudo nano /etc/httpd/conf.d/blog.conf - Paste in this configuration (adjust
ServerAliasif you want to includewww.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> - Save and exit (in nano, press
Ctrl+O, thenEnter, thenCtrl+X). - Test the configuration for syntax errors:
If you seesudo apachectl configtestSyntax 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:
- Create the same directory structure as above.
- Create a Nginx config file:
sudo nano /etc/nginx/conf.d/blog.conf - 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; } } - Test and restart Nginx:
sudo nginx -t sudo systemctl restart nginx
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.
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

