CentOS系统中无法启动NGINX:执行启动命令报错求助
Hey there, let's figure out why your NGINX instance is failing to start even though the config test passed. From the systemd logs you shared, we can see that the pre-start config check (/usr/sbin/nginx -t) succeeded, but the actual startup command (/usr/sbin/nginx) exited with status 1. Here are the steps to diagnose and fix this:
Check NGINX's detailed error logs
Systemd's summary log doesn't always show the full picture. The NGINX error log will have specific details about what went wrong. Run this command to view the latest entries:tail -n 30 /var/log/nginx/error.logLook for lines mentioning port conflicts, missing files, permission issues, or invalid runtime settings.
Verify no residual NGINX processes are running
Sometimes a stale NGINX process might be holding onto ports or resources, preventing a fresh start. Check for active NGINX processes:ps aux | grep nginxIf you see any processes listed (excluding the grep command itself), kill them with:
sudo killall nginxThen try starting NGINX again with
sudo systemctl start nginx.Check for port conflicts
NGINX typically listens on ports 80 (HTTP) and 443 (HTTPS). If another service is using these ports, NGINX can't start. Use this command to check which process is occupying port 80:sudo ss -tulpn | grep :80Replace
:80with:443to check the HTTPS port. If you find another service (like Apache, httpd, or a random app) using the port, stop that service or modify your NGINX config to listen on a different port.Validate directory permissions
NGINX runs under thenginxuser by default, and it needs write access to log directories and cache directories. Check the permissions for key directories:ls -ld /var/log/nginx /var/cache/nginxIf the owner isn't
nginx:nginx, fix it with:sudo chown -R nginx:nginx /var/log/nginx /var/cache/nginxRun the NGINX binary directly for verbose errors
Bypass systemd temporarily and run the NGINX startup command directly—this might output immediate, actionable errors that systemd doesn't capture:sudo /usr/sbin/nginxIf there's an issue, it should print a clear error message right away.
Start with the error log check first—it's usually the fastest way to pinpoint the problem. Let me know if you find specific errors and we can narrow it down further!
内容的提问来源于stack exchange,提问作者Sergei Petrov

