nginx 启动
1. 启动命令
在终端中使用以下命令启动 nginx:
sh
sudo systemctl start nginx
2. 配置文件
nginx 的配置文件通常位于 /etc/nginx/nginx.conf。
该文件包含以下要素:
events {}:处理连接和请求的配置
http {}:处理 HTTP 请求的配置
server {}:定义虚拟主机并配置其行为
3. 日志文件
nginx 将其日志写入下列文件:
access.log:记录所有请求
error.log:记录错误和警告
4. 进程管理
可以通过以下命令管理 nginx 进程:
systemctl status nginx:查看 nginx 的状态
systemctl stop nginx:停止 nginx
systemctl restart nginx:重新启动 nginx
示例:
sh
# 使用自定义配置文件启动 nginx
sudo nginx -c /path/to/custom.conf
# 查看 nginx 日志
tail -f /var/log/nginx/access.log
# 重新加载 nginx 配置而不重启
sudo systemctl reload nginx
![](https://img0.baidu.com/it/u=4035994658,1303021687&fm=253.jpg)