阅读234 返回首页    go 阿里云 go 技术社区[云栖]


mac系统下nginx的详细安装过程及使用(适合新手)

目录结构

Homebrew安装及说明

安装及说明

nginx启动,重启,关闭

? ? ・出错解决办法:只列出自己出的错

? ? ・其他说明:包括常用指令及修改配置等


? ? ? ??Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。

? ? ? Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、新浪、网易、腾讯等。

优点是可以在大多数 Unix like OS 上编译运行,并有 Windows 移植版。 Nginx 的1.4.0稳定版已经于2013年4月24日发布,一般情况下,对于新建站点,建议使用最新稳定版作为生产版本,已有站点的升级急迫性不高。Nginx 的源代码使用 2-clause BSD-like license。

? ? ?Nginx 是一个很强大的高性能Web和反向代理服务器,它具有很多非常优越的特性:

在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型


mac Sierra 10.12.4 ?


安装过程

Homebrew请绕过

Homebrew,因为这里介绍的安装方式需要brew命令

? ? ? 1.2 命令 ? ? ??ruby?-e?"$(curl?-fsSL?https://raw.githubusercontent.com/Homebrew/install/master/install)"?

? ?1.3命令说明:在“终端”中输入以上命令,系统会自动执行,只需在需要点击的时候根据提示点击就可以。下来就是安装nginx了


? 2.正式安装

? ? ?还是命令: ??brew?install?nginx?

? 一条命令搞定

nginx启动,重启,关闭

安装完以后,可以在终端输出的信息里看到一些配置路径:

? ? ? ? ? ? ?/usr/local/etc/nginx/nginx.conf (配置文件路径)

? ? ? ? ? ? /usr/local/var/www (服务器默认路径)

? ? ? ? ? ?/usr/local/Cellar/nginx/1.12.0 (安装路径)(我安装的是1.12.0,具体参照自己安装的版本)

? ?2.访问localhost:8080,成功说明安装好了,如果没有出现页面,可参照下面解决办法试着处理

? ?3.启动?

? ? ? 3.1进入安装路径 ? cd??/usr/local/Cellar/nginx/1.12.0?

? ? ? 3.2启动?sudo?./nginx

3.3重启?sudo./nginx?-s?reload?

3.4 判断配置文件是否正确 ?sudo?./nginx?-t?

3.5 nginx停止 ?首先查询nginx主进程号 ?ps -ef|grep nginx

正常停止???sudo?kill?-QUIT?主进程号

快速停止???sudo?kill?-TERM?主进程号

出错解决办法

?sudo ./nginx

? ? ? ? ? ?nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

? ? ? ? ? ?nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

? ? ? ? ? ?nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

? ? ? ? ? ?nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

? ? ? ? ? ?nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

其他说明

? ? ? nginx -V 查看版本,以及配置文件地址
? ? ? nginx -v 查看版本
? ? ? nginx -c filename 指定配置文件
? ? ? nginx -h 帮助

? ? ? sudo?nginx

? ? ? #测试配置是否有语法错误

? ??

? ? ? ? ?执行命令:

         sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf

? ? ? ? ?找到目录下的 php-fpm 文件

         /private/etc/php-fpm.conf

? ? ? ? ?找到32行的 error_log ,改为(正行替换,注意 ‘;’ 和空格):

         error_log = /usr/local/var/log/php-fpm.log

? ? ? ? ?否则 php-fpm 时会报错:

   ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)

? ?打开 nginx.config 文件

        /usr/local/etc/nginx/nginx.conf

? ? ? ? ? 找到 server 的 location 配置,给 index 加一个 index.php

     location / {
         root   html;
         index  index.html index.htm index.php;
     }

? ? ? ? ?并打开 server 下被注释的 location ~.php$(即删除代码前面的 ‘#’),如下:

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    include        fastcgi_params;
}

? ? ? ? 并修改 fastcgi_param 参数

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
改为
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

  sudo nginx
  sudo php-fpm

? ? ? ?然后访问localhost:8080,看到配置信息,就说明 ok 了

? ? 修改 nginx.conf 后,重载配置文件

   sudo nginx -s reload

? ?停止 nginx 服务器

  sudo nginx -s stop

? ?停止 php-fpm可以直接在 Activity Monitor 中停止。也可以使用脚本来停。

最后更新:2017-05-09 14:31:37

  上一篇:go 服务器RAID信息丢失怎么恢复数据?
  下一篇:go 聊聊淘宝天猫个性化推荐技术演进史