安装nginx,还是在mac上面用brew比较方便。

首先,brew install nginx,提示改权限

sudo chown -R $(whoami) /usr/local

然后brew install nginx,下载一些包始终太慢。

然后查看 brew --cache,发现缓存在 

/Users/baidu/Library/Caches/Homebrew

在下载慢的包,浏览器下载好放在这个目录,然后再次 brew install nginx 成功。

启动命令:brew services start nginx

然后http://127.0.0.1:8080/ 可以访问:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com. Thank you for using nginx.

查看版本:

$ nginx -v
nginx version: nginx/1.10.1

默认的nginx配置文件是在

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

root目录是在

/usr/local/Cellar/nginx/1.10.1/html

本身Nginx启动过程中的日志是在:

/usr/local/var/log/nginx/error.log
access.log

在Nginx的配置文件中打开日志后:

error_log  logs/error.log;
对应的是: /usr/local/Cellar/nginx/1.10.1/logs/

Mac默认的Php和php-fpm安装了:

$ which php
/usr/bin/php
$ which php-fpm
/usr/sbin/php-fpm
$ ls /etc/php
php-fpm.conf.default php.ini.default
$ php -v
PHP 5.5.30 (cli) (built: Oct 23 2015 17:21:45)

启动php-fpm前要准备好配置文件:

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

然后 php-fpm , 仍然报下面的错
$ php-fpm
[04-Oct-2016 16:46:40] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2) 需要
sudo vi /private/etc/php-fpm.conf
改两个地方:
error_log = /usr/local/var/log/php-fpm.log
pid = /usr/local/var/run/php-fpm.pid 然后php-fpm
php示例文件
<?php
echo "hi";
?> 然后 php -f hi.php
可以运行

然后我尝试把端口设成80,但是在这个error log:

/usr/local/var/log/nginx/error.log 报错:

2016/10/04 17:00:12 [emerg] 26905#0: bind() to 0.0.0.0:80 failed (13: Permission denied)

所以只好改成7080

然后发现php文件始终是在浏览器页面报这个错:

"File not found",然后在后台日志报这个错:

2016/10/04 17:01:39 [error] 27052#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1:7080"

在网上搜索之后,需要把/usr/local/etc/nginx/nginx.conf 里面 fastcgi_param里面的 /scripts$fastcgi_script_name; 改成 $document_root$fastcgi_script_name; 重启之后即可。

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

在/usr/local/Cellar/nginx/1.10.1/html放一个index.php,内写:

<?php
echo "Here is php index";
phpinfo();
?>

然后访问:http://127.0.0.1:7080/index.php 成功显示:Here is php index

————————————————————————————

以下为配置文件:

location ~ 区分大小写 ~* 不区分大小写

这篇文章可以看看:

http://www.cnblogs.com/top5/archive/2011/03/04/1970633.html

例子:

location = / {
# 只匹配 / 查询。
[ configuration A ]
} location / {
# 匹配任何查询,因为所有请求都已 / 开头。但是正则表达式规则和长的块规则将被优先和查询匹配。
[ configuration B ]
} location ^~ /images/ {
# 匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
[ configuration C ]
} location ~* \.(gif|jpg|jpeg)$ {
# 匹配任何已 gif、jpg 或 jpeg 结尾的请求。然而所有 /images/ 目录的请求将使用 Configuration C。
[ configuration D ]
} 例子请求: / -> configuration A /documents/document.html -> configuration B /images/1.gif -> configuration C /documents/1.jpg -> configuration D 注意:按任意顺序定义这4个配置结果将仍然一样。

----------------------------

Nginx安装及配置文件解释的更多相关文章

  1. Nginx安装及配置文件nginx.conf详解

    1.安装Nginx 在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcre-devel和zlib-devel软件库. 下面是Nginx安装过程: wget http ...

  2. Nginx安装与配置文件nginx.conf详解

    引用“http://ixdba.blog.51cto.com/2895551/790611” 1.安装Nginx在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcr ...

  3. ubuntu nginx 安装以及配置文件详解

    1.到nginx官网下载源码包.最好下载稳定版本,nginx官网http://www.nginx.org/ 2.安装nginx依赖包运行命令: sudo apt-get install libssl- ...

  4. Nginx安装与配置文件解析

    导读 Nginx是一款开放源代码的高性能HTTP服务器和反向代理服务器,同时支持IMAP/POP3代理服务,是一款自由的软件,同时也是运维工程师必会的一种服务器,下面我就简单的说一下Nginx服务器的 ...

  5. 01 - nginx - 安装、配置文件、默认网站、虚拟主机

    一.运维: . 介绍服务器. 服务器逻辑: 服务器选择 操作系统 部署逻辑 业务环境部署逻辑 业务部署图 软件部署文档 日常维护文档 测试 开发上传代码到源码系统 上线 - 测服务器,内测 预发布测试 ...

  6. nginx安装及配置文件详解

    一)nginx安装及模块讲解 1.1.nginx安装步骤 mkdir /soft wget http://nginx.org/download/nginx-1.12.0.tar.gz tar zxf ...

  7. nginx 安装和配置文件说明

    1. 安装依赖包 yum install gcc gcc+ yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel 2 ...

  8. Nginx安装部署以及配置文件解析

    Nginx 中的 Location 指令 是NginxHttpCoreModule中重要指令.Location 指令,是用来为匹配的 URI 进行配置,URI 即语法中的”/uri/”,可以是字符串或 ...

  9. Linux centosVMware 自动化运维Ansible介绍、Ansible安装、远程执行命令、拷贝文件或者目录、远程执行脚本、管理任务计划、安装rpm包/管理服务、 playbook的使用、 playbook中的循环、 playbook中的条件判断、 playbook中的handlers、playbook实战-nginx安装、管理配置文件

    一.Ansible介绍 不需要安装客户端,通过sshd去通信 基于模块工作,模块可以由任何语言开发 不仅支持命令行使用模块,也支持编写yaml格式的playbook,易于编写和阅读 安装十分简单,ce ...

随机推荐

  1. 搭建简单的CGI应用程序

    原文来源于<核心编程3>第10章web编程 一.静态文件+脚本文件 1.首先开启cgiweb服务器 python2 -m CGIHTTPServer 8000 看到如下反应 2.服务器目录 ...

  2. [实战]MVC5+EF6+MySql企业网盘实战(9)——编辑文件名

    写在前面 上篇文章实现了文件的下载,本篇文章将实现编辑文件名的功能. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网盘实战(1) ...

  3. loadrunner 分用户日志

    loadrunner 分用户日志 loadrunner在run脚本时,模拟多用户并发场景下,通常需要分别关注每个用户的脚本执行日志,可以按照以下操作进行: 在“Run Load Tests”中选择需要 ...

  4. Wannafly挑战赛18 B - 随机数

    思路:化简公式,Pn 表示 进行n 次操作,有奇数次1的概率 Pn = (1 - x) * Pn - 1  + x * (1 - Pn - 1) 得通项公式 Pn = (1 - (1 - 2 * x) ...

  5. 洛谷P2047 [NOI2007]社交网络 [图论,最短路计数]

    题目传送门 社交网络 题目描述 在社交网络(social network)的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题.在一个社交圈子里有n个人,人与人之间有不同程度的关系. ...

  6. 洛谷——P2071 座位安排 seat.cpp/c/pas

    P2071 座位安排 seat.cpp/c/pas 题目背景 公元二零一四年四月十七日,小明参加了省赛,在一路上,他遇到了许多问题,请你帮他解决. 题目描述 已知车上有N排座位,有N*2个人参加省赛, ...

  7. 实验吧--隐写术--九连环--WriteUp

    题目: http://ctf5.shiyanbar.com/stega/huan/123456cry.jpg 是一张图: 放到binwalk查看一下 发现存在压缩文件. 使用-e参数将文件分离 打开文 ...

  8. appengine 云计算。 部署web网络。

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha appengine 可以 不用手动启动像服务器. 在eclipse中 这两个sdk 配好 ...

  9. 【51Nod 1190】最小公倍数之和 V2

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1190 \[ \begin{aligned} &\sum_{i=a ...

  10. LCA(最近公共祖先)--tarjan离线算法 hdu 2586

    HDU 2586 How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...