启动 Nginx 服务器的步骤如下(根据操作系统不同有所差异):
sudo systemctl start nginx
或(旧版系统):
sudo service nginx start
sudo systemctl enable nginx
sudo systemctl status nginx
正常会显示 active (running)
。
进入 Nginx 安装目录(如 C:\nginx
),执行:
start nginx
或直接双击 nginx.exe
。
访问 http://localhost
,若看到欢迎页即成功。
brew services start nginx
或手动启动:
sudo nginx
brew services list | grep nginx
端口冲突(如 80 端口被占用):
sudo netstat -tulnp | grep 80
修改 Nginx 配置 listen
端口后重载:
sudo nginx -s reload
权限问题:
sudo chown -R www-data:www-data /var/www/html # Ubuntu
测试配置文件语法:
sudo nginx -t
强制停止 Nginx:
sudo pkill -9 nginx
功能 | 命令 |
---|---|
启动 | sudo systemctl start nginx |
停止 | sudo systemctl stop nginx |
重启 | sudo systemctl restart nginx |
重载配置(不中断) | sudo nginx -s reload |
如果仍有问题,请提供错误日志(默认路径:/var/log/nginx/error.log
)。