Amazon EC2 Ubuntu 17.04 Nginx配置phpMyAdmin子域名失败求助
Hey there, let's work through fixing your phpMyAdmin subdomain issue step by step. Based on the configs you shared, here are the key checks and adjustments to get things working:
1. Validate Nginx Config Syntax
First up, make sure your Nginx configurations don't have any syntax errors—invalid configs will prevent Nginx from loading properly. Run this command to check:
sudo nginx -t
If you see errors (like missing semicolons or incorrect paths), fix them immediately. A successful check will output test is successful.
2. Fix the phpMyAdmin Root Path
Your current phpMyAdmin config uses /usr/share/nginx/html as the root directory, but Ubuntu's default phpMyAdmin installation lives at /usr/share/phpmyadmin. Let's confirm this path exists:
ls /usr/share/phpmyadmin
If the directory is present, update the root directive in your phpmyadmin config file to:
root /usr/share/phpmyadmin;
This ensures Nginx knows where to find phpMyAdmin's core files.
3. Align PHP-FPM Socket Path
Notice the mismatch in php-fpm socket paths between your two configs:
defaultuses/run/php/php7.0-fpm.sockphpmyadminuses/var/run/php7.0-fpm.sock
Ubuntu 17.04 typically uses the /run/php/ path for php7.0-fpm sockets. Update the fastcgi_pass line in your phpMyAdmin config to match:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
This fixes potential connection failures between Nginx and the PHP processor.
4. Verify DNS & EC2 Security Group Settings
- DNS Propagation: Run
nslookup phpmyadmin.domain.comordig phpmyadmin.domain.comto confirm the subdomain points to your EC2 instance's public IP. If not, wait for DNS propagation (can take up to 24 hours) or double-check your AWS Route 53 records. - Security Group Rules: Ensure your EC2 security group allows inbound HTTP traffic (port 80) from your IP address (or
0.0.0.0/0for public access). Missing this rule will block all external requests to your subdomain.
5. Restart Services to Apply Changes
After updating your configs, restart Nginx and php-fpm to load the new settings:
sudo systemctl restart nginx sudo systemctl restart php7.0-fpm
6. Check Nginx Error Logs for Clues
If you still can't access the subdomain, pull the latest Nginx error logs to identify specific issues:
tail -n 20 /var/log/nginx/error.log
Logs will show details like file permission issues, missing files, or php-fpm connection failures.
Corrected phpMyAdmin Config Example
Here’s what your fixed phpmyadmin config should look like:
# phpMyAdmin子域名配置 server { listen 80; root /usr/share/phpmyadmin; index index.php index.html index.htm; server_name phpmyadmin.domain.com; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Give these steps a try, and let me know if you run into any roadblocks!
内容的提问来源于stack exchange,提问作者Omega

