AWS负载均衡器安装SSL证书后无法访问指定PHP页面求助
Got it, let's walk through the most likely causes and fixes for your issue where specific PHP pages like admin.php and vendor.php are redirecting to index.php after setting up SSL via AWS ALB and ACM. Since your main site and SSL are working fine, the problem is almost certainly in routing rules or web server configuration—here's how to track it down:
1. Check AWS ALB Routing Rules
It’s common to accidentally set up a "catch-all" rule that forces every request to index.php, even for specific pages. Here’s what to do:
- Log into the AWS Console, navigate to your Load Balancer, and go to the Listeners tab.
- Look at your HTTPS (443) listener rules:
- Verify there are explicit rules for
/admin.phpand/vendor.phpthat forward traffic to your EC2 target group. If these rules don’t exist, add them—make sure they take priority over any catch-all rules (like a rule matching/*). - Confirm your target group’s health checks are passing. If the ALB thinks your EC2 instances are unhealthy, it might trigger unexpected redirects (though this is less likely for your specific case).
- Verify there are explicit rules for
2. Validate Your EC2 Web Server Configuration (Apache/Nginx)
This is the most probable culprit. SSL setup can sometimes activate or modify rewrite rules that override access to specific PHP pages.
For Apache Users:
- Check your
.htaccessfile (in your site’s root directory) or virtual host config files (under/etc/apache2/sites-available/) for rewrite rules.- If you see something like
RewriteRule ^(.*)$ index.php [L], this is a catch-all rule that redirects everything toindex.php. Add exceptions for your pages:RewriteCond %{REQUEST_URI} !^/admin.php RewriteCond %{REQUEST_URI} !^/vendor.php RewriteRule ^(.*)$ index.php [L] - Ensure the
mod_rewritemodule is enabled: runsudo a2enmod rewrite, then restart Apache withsudo systemctl restart apache2. - Double-check that your SSL-enabled virtual host has the same permissions and rules as your HTTP one—don’t let the SSL config block access to these pages.
- If you see something like
For Nginx Users:
- Open your site’s config file (under
/etc/nginx/sites-available/) and look at thetry_filesdirective.- The default
try_files $uri $uri/ /index.php?$query_string;will fall back toindex.phpif a file isn’t found, but if your PHP files exist, this might be a fastcgi or permission issue. Add explicit location blocks for your pages:location /admin.php { fastcgi_pass unix:/run/php/php8.1-fpm.sock; # Adjust to match your PHP version fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /vendor.php { fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # Keep the default catch-all for other paths location / { try_files $uri $uri/ /index.php?$query_string; } - Test your Nginx config with
sudo nginx -tto catch errors, then restart it withsudo systemctl restart nginx.
- The default
3. Verify PHP File Permissions & Existence
Sometimes the issue is simpler than you think—make sure your files are actually there and accessible:
- SSH into your EC2 instance, then navigate to your site’s root directory (usually
/var/www/html/). Runls -lto confirmadmin.phpandvendor.phpexist. - Check that the files are owned by the web server user (for Apache/Nginx, this is typically
www-data):- Fix permissions with
sudo chown www-data:www-data /var/www/html/admin.phpandsudo chown www-data:www-data /var/www/html/vendor.php.
- Fix permissions with
- Test access directly on the server with
curl http://localhost/admin.php. If this fails, you might have a PHP module missing or a syntax error in the PHP file itself.
4. Clear Browser & Redirect Caches
Old redirects can get stuck in browser cache, even if you’ve fixed the server-side issue:
- Try accessing the pages in incognito/private browsing mode to bypass cached redirects.
- Use
curl -v https://yourdomain.com/admin.phpto see the full HTTP response. Look for 3xx status codes and check where the redirect is coming from—this will confirm if it’s a server-side redirect or a client-side cache issue.
5. Double-Check ALB SSL & Listener Setup
While you said SSL is working, it’s worth a quick check:
- Confirm your ALB’s HTTPS listener is correctly associated with your ACM certificate.
- Verify the listener is forwarding traffic to the correct port on your EC2 instances (usually 80 if you’re terminating SSL at the ALB, or 443 if you’re re-encrypting traffic to EC2).
内容的提问来源于stack exchange,提问作者Joe

