第一种方案:

1. 执行命令 :open /usr/local/etc/nginx 打开nginx安装目录

nginx安装目录默认位置有:(找到适合你的)

  • /etc/nginx/nginx.conf,

  • /usr/local/etc/nginx/nginx.conf,或

  • /usr/local/nginx/conf/nginx.conf

nginx启动或者重启失败,报错nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

2.放开注释,改为:pid /usr/local/etc/nginx/logs/nginx.pid;

nginx启动或者重启失败,报错nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

3.执行命令:mkdir /usr/local/etc/nginx/logs/usr/local/etc/nginx目录下创建目录logs

4.启动nginx

第二种方案:

找到你的nginx.conf的文件夹目录

然后运行 nginx -c /usr/local/etc/nginx/nginx.conf命令 

再运行(sudo)nginx -s reload 重启nginx就可以了