安装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. 找到最大或最小的N个元素---heapq模块

    堆排序heapq的用法 基本用法: 复杂数据结构: # coding=utf- # example.py # Example of using heapq to find the N smallest ...

  2. ASP.NET MVC 获取计算机字体

    //加载计算机上可用的字体 public string LoadFonts() { try { var fontCollection = new InstalledFontCollection(); ...

  3. 【51nod】2026 Gcd and Lcm

    题解 话说LOJ说我今天宜学数论= =看到小迪学了杜教筛去蹭了一波小迪做的题 标解的杜教筛的函数不懂啊,怎么推的毫无思路= = 所以写了个复杂度稍微高一点的?? 首先,我们发现f是个积性函数,那么我们 ...

  4. php将长字符串拆分为指定最大宽度的字符串数组

    /** * 将字符串拆分为指定最大宽度的字符串数组.单字节字符宽度为1,多字节字符通常宽度为2 * @param string $msg 要拆分的字符串 * @param int $width 结果数 ...

  5. openssl 获取证书中的公钥

    PEM 格式 1.  FILE *fp = fopen("xx.pem", "r"); 2.  X509 *cert = PEM_read_X509(fp, N ...

  6. RecyclerView悬浮标题

    效果图:        1.顶部会悬浮章的部分 2.第二章上滑会推挤第一章 3.第二章下拉会带出第一章 4.并不是所有时候都有悬浮部分(为什么这条标红,因为市面上几乎所有的悬浮都是必须存在且在顶部,害 ...

  7. POJ3292 Semi-prime H-numbers [数论,素数筛]

    题目传送门 Semi-prime H-numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10871   Acce ...

  8. 洛谷P3275 [SCOI2011]糖果 [差分约束系统]

    题目传送门 糖果 题目描述 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比 ...

  9. windows下srand48()和drand48()的问题

    前几天在windows下用MINGW编译一段代码时,出现了错误提示说srand48()和drand48()的未定义,去网上搜了下,发现好多人也遇到了同样的问题,大约有两种解决方案: 第一个就是说gcc ...

  10. 【四边形不等式】POJ1160[IOI2000]-Post Office

    [题目大意] v个村庄p个邮局,邮局在村庄里,给出村庄的位置,求每个村庄到最近邮局距离之和的最小值. [思路] 四边形不等式,虽然我并不会证明:( dp[i][j]表示前i个村庄建j个邮局的最小值,w ...