环境信息:

Mac OS X 10.11.1

Homebrew  0.9.5

正文

一、安装 Nginx

1.终端执行:

1
2
brew search nginx
brew install nginx

当前版本 1.6.2

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

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

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

/usr/local/Cellar/nginx/1.6.2  (貌似是安装路径)

二、访问localhost:8080

Nginx 默认8080端口,这时已经可以访问了:

localhost:8080

会有一个默认欢迎界面。

三、修改 php-fpm 文件

1.执行命令:

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

2.找到目录下的 php-fpm 文件

1
/private/etc/php-fpm.conf

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

1
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 配置

1.打开 nginx.config 文件

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

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

1
2
3
4
location / {
  root  html;
  index index.html index.htm index.php;
}

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

1
2
3
4
5
6
7
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;
}

4.并修改 fastcgi_param 参数

1
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

改为

1
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

五、创建 index.php

在 /usr/local/var/www 目录下,删除 index.html,创建 index.php,输入

1
<?php phpinfo(); ?>

六、启动相关服务

1
2
sudo nginx
sudo php-fpm

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

七、其他命令

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

1
sudo nginx -s reload

停止 nginx 服务器

1
sudo nginx -s stop

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

八、可能出现的问题

1.访问 index.php 报 403 Forbidden.查看(四.2)步骤中,是否在 index 后添加 index.php。

2.访问 index.php 报 File not found.查看(四.4)中,fastcgi_param 参数是否修改。

转载于脚本之家(http://www.jb51.net/article/105492.htm)

Mac 下配置Nginx安装环境配置详细说明的更多相关文章

  1. Mac下安装nginx并配置SSL实现Https的访问

    一.nginx安装 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/insta ...

  2. Linux下的Nginx的配置+Tomcat启动

    Linux下的Nginx的配置 首次如果你只仅主机模式,那么请你切换到桥接模式或者net模式. 1.安装编译工具及库文件 yum -y install make zlib zlib-devel gcc ...

  3. Mac下Maven安装与配置

    Mac下Maven安装与配置 下载maven http://maven.apache.org/download.cgi main->download菜单下的Files 下载后解压在Documen ...

  4. CentOS 下 安装 nginx 执行配置命令 ./configure 报错

    CentOS 下 安装 nginx 执行配置命令 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx 时提示以下错误: checkin ...

  5. Mac 下 安装 Nginx

    ---恢复内容开始--- Mac 下 安装nginx 首先确定自己有安装homebrew 安装 nginx brew install nginx 启动nginx 1.15版本下 安装是 直接在ngin ...

  6. mac下安装nginx及相关配置

    1. 安装 Homebrew   首先 homebrew是什么?它是Mac中的一款软件包管理工具,通过brew可以很方便的在Mac中安装软件或者是卸载软件.不了解的同学看以看官网(https://br ...

  7. Linux下安装Nginx并配置一个图片服务器

    首先安装nginx安装环境 nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境. gcc 安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没 ...

  8. 【工匠大道】Mac下Java开发环境配置简述

    本文地址 原文地址 分享提纲: 1. 下载JDK1.7 2. 配置java_home 3 .安装tomcat 4 .安装eclipse或者myeclipse 5.  mysql安装 破解版下载请参考M ...

  9. Mac下golang开发环境配置

    go语言在开发效率和运行效率中的优势让很多人青睐,所以有倾向打算转向go语言的开发. 下面介绍在Mac OS X中golang的开发环境配置. 1.安装brew brew是一个mac下的由ruby开发 ...

随机推荐

  1. PR(Precision-Recall)曲线和mAP指标

    来自: https://www.zhihu.com/question/41540197 https://www.douban.com/note/518998773/ 作者:水哥链接:https://w ...

  2. python scrapy 插入数据库的操作

    需要安装这个 pymysql 写法还是很简单的 # -*- coding: utf-8 -*- # Define your item pipelines here # # Don't forget t ...

  3. AJAX简单实例

    越用AJAX越觉得它的强大.好用. 平常我们提交表单,是直接通过action属性,直接向后台提交数据. 我们也可以用AJAX向后台提交数据.例如: 这是一个表单,两个字段:notice,scort,保 ...

  4. ssh架构之hibernate(二)进阶学习

    1.JPA入门 JPA的认识:JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中Java持久层AP ...

  5. com.android.dx.command.Main with arguments

    Error:Execution failed for task ':jingyeyun:transformClassesWithDexForDebug'.> com.android.build. ...

  6. Bootstrap Tooltip

    [Bootstrap Tooltip] 1.设置Tooltip: 1)data-toggle="tooltip" 2)data-placement="top", ...

  7. cacti有图无数据解决办法

    Cacti 安装不久,图像界面出来了,但是一直没有数据. Cacti 日志中的错误或警告也都一个个全部解决.有些需要访问文件的权限也都有了. 1.system utilities –>Rebui ...

  8. 解题(PockerCompare-扑克牌比较大小)

    题目描述 扑克牌游戏大家应该都比较熟悉了,一副牌由54张组成,含3~A.2各4张,小王1张,大王1张.牌面从小到大用如下字符和字符串表示(其中,小写joker表示小王,大写JOKER表示大王):3 4 ...

  9. springboot 缓存

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  10. poj 1789 prime

    链接:Truck History - POJ 1789 - Virtual Judge  https://vjudge.net/problem/POJ-1789 题意:先给出一个n,代表接下来字符串的 ...