MAC安装Nginx 以及使用中遇到的坑
来源:     阅读:719
云上智慧
发布于 2020-04-24 21:00
查看主页

一.安装

brew install nginx
注释: brew 安装
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. 安装完之后,可以在终端看到路径信息
    /usr/local/etc/nginx/nginx.conf (配置文件路径) /usr/local/var/www (服务器默认路径) /usr/local/Cellar/nginx/1.8.0 (安装路径)

  2. 假如是macOS 1.12以上的系统,在安装过程中可能会出现”warning”,说是不支持该版本的操作系统,可以暂时先忽略它。

二. 启动

  1. 在终端输入 ps -ef|grep nginx看能否有启动
  2. 假如没有启动执行以下命令启动/usr/local/Cellar/nginx/1.8.0/bin/nginx -c /usr/local/etc/nginx/nginx.conf 肯定要注意路径能否是自己的安装路径
  3. cd 到/usr/local/Cellar/nginx/1.8.0/bin/ 目录下 执行sudo ./nginx
  4. 这时候假如成功访问localhost:8080,说明成功安装和启动好了。

三. 中止

  1. 终端输入ps -ef|grep nginx获取到nginx的进程号, 注意是找到“nginx:master”的那个进程号
  2. kill -QUIT 15800 (从容的中止,即不会立刻中止)
    Kill -TERM 15800 (立刻中止)
    Kill -INT 15800 (和上面一样,也是立刻中止)

四、重启

  1. 假如配置文件错误,则将启动失败,所以在启动nginx之前,需要先验证在配置文件的正确性,如下表示配置文件正确
    promote:bin yangqianhua$ /usr/local/Cellar/nginx/1.8.0/bin/nginx -t -c /usr/local/etc/nginx/nginx.conf
    nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
  2. 重启有两种方法

Nginx 遇到的坑

nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied) 2018/09/18 16:53:12 [emerg] 9734#0: open() "/usr/local/Cellar/nginx/1.15.3/logs/error.log" failed (2: No such file or directory)

操作 cd /usr/local/Cellar/nginx/1.15.3/ 新建logs目录增加error.log文件, 执行sudo nginx 出现如下错误

nginx: [warn] 1024 worker_connections exceed open file resource limit: 256 localhost:bin hello_xie$ nginx: [warn] 1024 worker_connections exceed open file resource limit: 256 -bash: nginx:: command not found localhost:bin hello_xie$ nginx: [warn] 1024 worker_connections exceed open file resource limit: 256 -bash: nginx:: command not found

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

另一种处理方案(stackoverflow)

到 nginx.conf 文件增加 worker_rlimit_nofile 1024;这种入侵性更小, 推荐使用

Mac 403 Forbidden

要在Nginx.conf文件 最开始的地方加权限
user root owner 而后重启或者者重新加载Nginx

追加1

"/usr/local/var/run/nginx/client_body_temp/0000000004" failed (13: Permission denied), client: 127.0.0.1, server: localhost, request: "POST /vip/doc/docs?userId=admin&userName=%E7%AE%A1%E7%90%86%E5%91%98&sysCode=ivs&businessModel=frameworkAppr HTTP/1.1", host: "localhost:3000", referrer: "http://localhost:3000/"

免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 系统环境 服务器应用
相关推荐
十道或者许你不熟练的前台HTML5的经典面试题
如何在Linux中使用Tail命令
初级前台必看——2020最完整大厂高频面试真题分享(含答案)!
给初学者的RxJava2.0教程(十)
《菜鸟教程》-TypeScript安装
首页
搜索
订单
购物车
我的