在运行Apache的Plesk服务器上配置Nginx托管静态网站时遇启动错误的求助
Hey there! Let's work through this problem step by step—since you're new to VPS and Linux, I'll keep things clear and actionable.
First, Fix the Nginx Startup Error (The Brotli Issue)
The immediate reason Nginx won't start is this critical error:
nginx: [emerg] unknown directive "brotli" in /etc/nginx/conf.d/brotli.conf:1
This means your Nginx installation doesn't have the Brotli compression module enabled or installed, but a config file is trying to use Brotli-related commands. Here's how to fix it:
Check if Brotli is already installed
Run this command in your terminal to see what modules your Nginx has loaded:nginx -VLook for
--with-http_brotli_moduleor--with-http_brotli_static_modulein the output. If you don't see either, the module is missing.Option 1: Install the Brotli Module (Recommended for Long-Term)
If you're on a Debian/Ubuntu system (common with Plesk), install the official Nginx Brotli module:sudo apt update sudo apt install nginx-module-brotliThen edit your main
nginx.conffile (usually at/etc/nginx/nginx.conf) and add these lines at the very top, before thehttpblock:load_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so;Save the file, then test your Nginx config to confirm no syntax errors:
sudo nginx -tIf you see "nginx: configuration file /etc/nginx/nginx.conf test is successful", restart Nginx:
sudo systemctl restart nginxOption 2: Temporarily Disable Brotli Config (Quick Fix)
If you don't need Brotli compression right now, just comment out all lines in the problematic config file. Open it with a text editor like nano:sudo nano /etc/nginx/conf.d/brotli.confAdd a
#at the start of every line to comment them out, save (Ctrl+O) and exit (Ctrl+X). Runsudo nginx -tto test, then restart Nginx if the test passes.
Next: Set Up Your Static Site to Coexist With Plesk's Apache/Nginx Setup
Now that Nginx can start, let's make sure your static site is accessible without breaking your existing WordPress sites. Since Plesk manages its own Nginx/Apache configs, manually editing /etc/nginx/sites-available might lead to conflicts later (Plesk could overwrite these files during updates). A better approach is:
Use Plesk to Configure the Static Site (Easiest Method)
- Log into your Plesk control panel.
- Add the
bloggrammer.comdomain if you haven't already. - Go to the domain's Hosting Settings:
- Under "Web Server", select Nginx only (instead of "Apache + Nginx reverse proxy")—this tells Plesk to use Nginx directly for this static site, no need to route through Apache.
- Set the "Document root" to
/var/www/bloggrammer.com.
- Save the settings—Plesk will automatically generate the correct Nginx config for you, no manual editing required.
If You Want to Keep Using Your Manual Nginx Config
If you prefer to stick with your existing config, you need to make sure Plesk doesn't interfere with it:- Ensure your static site's Nginx config keeps using port 8080 (since Apache is already using port 80).
- To let visitors access
bloggrammer.comon the default port 80, set up a reverse proxy in Plesk for this domain:- In Plesk, go to the domain's Apache & Nginx Settings.
- Under "Additional Nginx directives", add:
location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } - Save the settings—this will make Plesk's Nginx (listening on port 80) forward requests for
bloggrammer.comto your static site's Nginx instance on 8080.
Quick Tips to Avoid Future Issues
- Don't delete default Nginx config files—instead, comment out their content if you don't need them. Deleting files can cause unexpected behavior.
- Whenever you edit Nginx configs, always run
sudo nginx -tto test for syntax errors before restarting the service.
备注:内容来源于stack exchange,提问作者crammer

