Ubuntu 17.10下Nginx Server Blocks配置无效问题求助
Hey there! Let's troubleshoot your Nginx server blocks issue step by step—since you're running Ubuntu 17.10 and followed a 16.04 guide, small version-specific nuances might be tripping things up. Here's what to check:
1. Validate Your Server Block Structure
Your shared snippet only shows the comment header—make sure your full config has all core directives. A basic working block should look like this (replace placeholders with your actual details):
server { listen 80; listen [::]:80; root /var/www/your_domain/html; index index.php index.html index.htm; server_name your_domain www.your_domain; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.1-fpm.sock; } location ~ /\.ht { deny all; } }
Double-check that root points to your actual website files directory, and server_name matches your domain/test hostname (like localhost for local testing).
2. Make Sure the Server Block is Enabled
Ubuntu 17.10 uses the same sites-available/sites-enabled setup as 16.04, but symlinks can easily go wrong:
- Confirm your config file lives in
/etc/nginx/sites-available/(let's call ityour_domain.conf) - Create a symlink to enable it:
sudo ln -s /etc/nginx/sites-available/your_domain.conf /etc/nginx/sites-enabled/ - Remove the default config symlink if you don't need it:
sudo unlink /etc/nginx/sites-enabled/default
3. Test for Nginx Syntax Errors
A tiny typo can break everything—run this to validate your config:
sudo nginx -t
If you get an error, fix the line it flags (common issues: missing semicolons, incorrect file paths, or invalid directives).
4. Verify PHP-FPM is Running & Socket Path is Correct
Since you're using PHP 7.1, ensure the FPM service is active and the socket path in your server block matches:
- Check PHP-FPM status:
sudo systemctl status php7.1-fpm - Start it if it's not running:
sudo systemctl start php7.1-fpm - Confirm the socket exists:
If it doesn't, your PHP-FPM config might use a TCP port instead (likels /run/php/php7.1-fpm.sock127.0.0.1:9000)—adjust thefastcgi_passline in your server block accordingly.
5. Clear Cache & Test Directly
Browsers often cache old responses—try accessing your site in incognito mode, or run this to get raw HTTP headers:
curl -I your_domain
Look for a 200 OK status, or clues about redirects/errors in the output.
6. Check Nginx Error Logs for Clues
If nothing else works, real-time logs will tell you exactly what's broken:
sudo tail -f /var/log/nginx/error.log
Run this command, then try accessing your site—you'll see live error messages pointing to issues like missing files, permission problems, or misconfigured directives.
内容的提问来源于stack exchange,提问作者flashydev

