新手求助:不使用Route 53将域名映射到Amazon EC2实例的详细步骤
Hey there! I’ve walked through this exact setup multiple times, so let’s break down how to map your domain to your Bitnami WordPress EC2 instance without using AWS Route 53. Follow these steps carefully, and you’ll be up and running in no time.
1. Get Your EC2 Instance’s Stable Public IP (Use Elastic IP)
Regular public IPs change when you restart your instance—so always use an Elastic IP for a fixed address:
- Log into your AWS Console, navigate to the EC2 dashboard.
- Locate your Bitnami WordPress instance, then go to
Actions > Networking > Manage Elastic IPs. - If you don’t have an Elastic IP yet, click
Allocate Elastic IP addressand confirm the allocation. - Select the new Elastic IP, click
Actions > Associate Elastic IP address, pick your EC2 instance from the dropdown, and save. - Jot down this Elastic IP—you’ll need it for DNS setup later.
2. Update EC2 Security Group to Allow Web Traffic
Your instance’s security group needs to let HTTP/HTTPS traffic reach it:
- Go back to your EC2 instance details, click the linked security group under the "Security" section.
- In the
Inbound rulestab, clickEdit inbound rules. - Add two new rules:
- Type:
HTTP, Protocol:TCP, Port range:80, Source:0.0.0.0/0(lets all users access your site via HTTP) - Type:
HTTPS, Protocol:TCP, Port range:443, Source:0.0.0.0/0(enables secure HTTPS access)
- Type:
- Make sure your SSH rule (port 22) is still present so you can log into the instance later.
- Save the rules.
3. Configure DNS Records at Your Domain Registrar
Head over to your domain registrar (like Namecheap, GoDaddy, etc.) to point your domain to the Elastic IP:
- Log into your registrar’s dashboard, find the
DNS ManagementorNameserverssection for your domain. - Add A Records (maps domains directly to IP addresses):
- For your root domain (e.g.,
yourdomain.com): Set Host Record to@, Value to your Elastic IP, TTL to300(5 minutes, speeds up propagation). - For the
wwwsubdomain (e.g.,www.yourdomain.com): Either add another A Record with Host Recordwwwand the same Elastic IP, or add a CNAME Record with Host Recordwwwpointing to@(your root domain).
- For your root domain (e.g.,
- Save the DNS changes. Note: Propagation can take 5 minutes to 24 hours, but usually completes within an hour.
4. Update Bitnami WordPress Configuration
This is the critical step—Bitnami uses specific config files to link your domain:
4.1 SSH Into Your EC2 Instance
Use your AWS key pair to log in via SSH. Open your terminal and run:
ssh -i "your-key-pair-file.pem" bitnami@your-elastic-ip
(Replace your-key-pair-file.pem with the path to your downloaded key pair, and your-elastic-ip with your instance’s Elastic IP.)
4.2 Update WordPress Core Settings
Edit the wp-config.php file to set your domain as the home and site URL:
sudo nano /opt/bitnami/apps/wordpress/htdocs/wp-config.php
Find or add the lines for WP_HOME and WP_SITEURL (add them at the bottom if missing):
define('WP_HOME','http://yourdomain.com'); define('WP_SITEURL','http://yourdomain.com');
(Replace yourdomain.com with your actual domain. If you plan to use HTTPS, change http to https now.)
Press Ctrl+O to save, then Ctrl+X to exit nano.
4.3 Update Apache Virtual Host Config
Bitnami uses Apache, so we need to update its config to recognize your domain:
First, edit the main Apache config:
sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami.conf
Find the <VirtualHost _default_:80> block, update ServerName and add a ServerAlias (for the www subdomain):
ServerName yourdomain.com ServerAlias www.yourdomain.com
Save and exit nano.
If you plan to use HTTPS (highly recommended), edit the SSL config too:
sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf
Find the <VirtualHost _default_:443> block and update ServerName and ServerAlias the same way:
ServerName yourdomain.com ServerAlias www.yourdomain.com
Save and exit.
4.4 Restart Apache to Apply Changes
Run this command to restart the Apache server:
sudo /opt/bitnami/ctlscript.sh restart apache
5. Verify the Setup
Wait for DNS propagation to finish, then open your browser and type in your domain. You should see your Bitnami WordPress site load correctly.
If you run into issues:
- Check DNS propagation: Run
nslookup yourdomain.comin your terminal—if it returns your Elastic IP, propagation is done. - Check Apache logs for errors: Run
tail /opt/bitnami/apache2/logs/error_logto debug issues. - Fix file permissions: If you modified files, run
sudo chown -R bitnami:bitnami /opt/bitnami/apps/wordpress/htdocsto ensure correct ownership.
Bonus: Enable Free SSL with Let’s Encrypt
Bitnami has a built-in tool to make this easy. Run:
sudo /opt/bitnami/bncert-tool
Follow the on-screen prompts to set up SSL—this will automatically update your config to use HTTPS and redirect HTTP traffic to HTTPS.
内容的提问来源于stack exchange,提问作者Aly Mansour

