nginx 通过homebrew安装在/usr/local/Cellar/nginx/1.27.0/bin目录里面
如果修改了/etc/hosts中的虚拟主机之后,
需要cd到/usr/local/Cellar/nginx/1.27.0/bin目录里面执行sudo nginx -s reload,如果是刚重启过电脑,会提示没有.pid文件存在,
那么此时需要执行的是sudo ./nginx,即先把nginx给启动起来;
cd /usr/local/Cellar/nginx/1.27.0/bin
sudo ./nginx
配置文件目录
/usr/local/etc/nginx/vhosts
如果需要重启php-fpm,可以在任何目录执行sudo killall php-fpm,然后执行sudo php-fpm;
sudo killall php-fpm
sudo php-fpm
如果需要重启php72,则可以运行brew services restart php@8.2;
brew services restart php@8.2
有时候nginx服务启动失败,比如端口被占用,往往发生在重启电脑的时候,此时一般是apache服务mac自
带的服务捣乱,可以先执行sudo apachectl stop 关闭apache服务
sudo apachectl stop
nginx 常用命令
Nginx 是一个高性能的 Web 服务器和反向代理服务器,以下是一些常用的 Nginx 命令:
1. 启动 Nginx
nginx
或:
systemctl start nginx # 在 systemd 系统(如 CentOS 7+、Ubuntu 16.04+)
或:
service nginx start # 适用于旧版本 Linux
2. 关闭 Nginx
立即停止(强制关闭)
nginx -s stop
或:
systemctl stop nginx
优雅停止(等待处理完请求再关闭)
nginx -s quit
3. 重启 Nginx
nginx -s reload
或:
systemctl restart nginx
或:
service nginx restart
4. 检查 Nginx 配置
nginx -t
如果配置正确,会输出:
nginx: configuration file /etc/nginx/nginx.conf test is successful
如果有错误,会显示具体错误信息,方便排查问题。
5. 重新加载配置(不中断服务)
nginx -s reload
或:
systemctl reload nginx
这个命令用于在不重启 Nginx 的情况下重新加载配置文件,非常适合在修改配置后使用。
6. 查看 Nginx 运行状态
systemctl status nginx
如果 Nginx 正在运行,会看到类似:
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since ...
7. 查看 Nginx 进程
ps aux | grep nginx
或:
pgrep -l nginx
8. 强制杀死 Nginx
如果 Nginx 进程无法正常关闭,可以使用:
pkill -9 nginx
或:
killall -9 nginx
9. 让 Nginx 在开机时自动启动
systemctl enable nginx
10. 禁止 Nginx 开机启动
systemctl disable nginx
这些是 Nginx 的常用命令,你是否需要更具体的使用案例,比如日志查看、反向代理配置等?