请求协助:将AWS ELB地址重定向至指定域名登录页面
Absolutely! Redirecting traffic from your direct ELB address to your desired custom domain path is completely achievable. Below are the most practical methods based on your AWS setup:
Method 1: Use Application Load Balancer (ALB) Built-in Redirect Rules
If you’re using an Application Load Balancer (the modern ELB variant), this is the cleanest approach—it handles redirects at the load balancer level without touching your backend servers:
- Navigate to the AWS EC2 Console → Load Balancers → Select your ALB.
- Go to the Listeners tab. Configure rules for both HTTP (port 80) and HTTPS (port 443) to cover all possible user access paths.
- For the HTTP listener:
- Click "Edit rules" → Add a new rule.
- Set the condition to Host header → Enter your ELB domain:
rotary-staging-1821321305.us-east-1.elb.amazonaws.com. - Set the action to Redirect with these parameters:
- Protocol:
HTTPS - Port:
443 - Host:
staging.rotaryisu.com - Path:
/rotary/frontend/web/site/login(keep the leading slash) - Query string: Choose "Keep" if you want to preserve query parameters, or "Discard" if not.
- Status code:
301 - Permanent Redirect(recommended for long-term changes and SEO) or302 - Temporary Redirect.
- Protocol:
- Repeat the same rule setup for the HTTPS listener to cover users accessing the ELB via HTTPS.
Method 2: Configure Backend Server Redirects (For Classic ELB or ALB Rules Aren’t an Option)
If you’re using a Classic Load Balancer or prefer to handle redirects at the backend, configure your web server (Nginx, Apache, etc.) to check the incoming Host header and redirect accordingly:
For Nginx:
Add this server block to your Nginx configuration file:
server { listen 80; # Add `listen 443 ssl;` here if your backend handles HTTPS directly server_name rotary-staging-1821321305.us-east-1.elb.amazonaws.com; # Redirect to your target URL, preserving query parameters return 301 https://staging.rotaryisu.com/rotary/frontend/web/site/login$request_uri; }
For Apache:
Add this to your .htaccess file or Apache virtual host configuration:
RewriteEngine On # Match requests to the ELB domain (case-insensitive) RewriteCond %{HTTP_HOST} ^rotary-staging-1821321305\.us-east-1\.elb\.amazonaws\.com$ [NC] # Redirect to the target path, preserving the original request URI RewriteRule ^(.*)$ https://staging.rotaryisu.com/rotary/frontend/web/site/login$1 [R=301,L]
Restart your web server after updating the config to apply changes.
Key Notes to Ensure Success:
- SSL Certificate: Make sure your target domain (
staging.rotaryisu.com) has a valid SSL certificate (e.g., from AWS Certificate Manager) to avoid browser security warnings. - Test the Redirect: Use
curl -I http://rotary-staging-1821321305.us-east-1.elb.amazonaws.comto verify the redirect returns a 301/302 status code and points to the correct URL. - Choose the Right Redirect Code: Use 301 for permanent changes (helps with search engine rankings) and 302 if you might adjust the redirect target later.
内容的提问来源于stack exchange,提问作者Kavendra

