Nginx安装及配置文件解释
安装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安装及配置文件解释的更多相关文章
- Nginx安装及配置文件nginx.conf详解
1.安装Nginx 在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcre-devel和zlib-devel软件库. 下面是Nginx安装过程: wget http ...
- Nginx安装与配置文件nginx.conf详解
引用“http://ixdba.blog.51cto.com/2895551/790611” 1.安装Nginx在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcr ...
- ubuntu nginx 安装以及配置文件详解
1.到nginx官网下载源码包.最好下载稳定版本,nginx官网http://www.nginx.org/ 2.安装nginx依赖包运行命令: sudo apt-get install libssl- ...
- Nginx安装与配置文件解析
导读 Nginx是一款开放源代码的高性能HTTP服务器和反向代理服务器,同时支持IMAP/POP3代理服务,是一款自由的软件,同时也是运维工程师必会的一种服务器,下面我就简单的说一下Nginx服务器的 ...
- 01 - nginx - 安装、配置文件、默认网站、虚拟主机
一.运维: . 介绍服务器. 服务器逻辑: 服务器选择 操作系统 部署逻辑 业务环境部署逻辑 业务部署图 软件部署文档 日常维护文档 测试 开发上传代码到源码系统 上线 - 测服务器,内测 预发布测试 ...
- nginx安装及配置文件详解
一)nginx安装及模块讲解 1.1.nginx安装步骤 mkdir /soft wget http://nginx.org/download/nginx-1.12.0.tar.gz tar zxf ...
- nginx 安装和配置文件说明
1. 安装依赖包 yum install gcc gcc+ yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel 2 ...
- Nginx安装部署以及配置文件解析
Nginx 中的 Location 指令 是NginxHttpCoreModule中重要指令.Location 指令,是用来为匹配的 URI 进行配置,URI 即语法中的”/uri/”,可以是字符串或 ...
- Linux centosVMware 自动化运维Ansible介绍、Ansible安装、远程执行命令、拷贝文件或者目录、远程执行脚本、管理任务计划、安装rpm包/管理服务、 playbook的使用、 playbook中的循环、 playbook中的条件判断、 playbook中的handlers、playbook实战-nginx安装、管理配置文件
一.Ansible介绍 不需要安装客户端,通过sshd去通信 基于模块工作,模块可以由任何语言开发 不仅支持命令行使用模块,也支持编写yaml格式的playbook,易于编写和阅读 安装十分简单,ce ...
随机推荐
- c# 递归异步获取本地驱动器下所有文件
//获取所有驱动器 string[] drives = Environment.GetLogicalDrives(); foreach (string driver in drives) { Cons ...
- Python 爬虫笔记(二)
个人笔记,仅适合个人使用(大部分摘抄自python修行路) 1.使用selenium(传送) selenium 是一套完整的web应用程序测试系统,包含了测试的录制(selenium IDE),编写及 ...
- 转:asm.js 和 Emscripten 入门教程
转:http://www.ruanyifeng.com/blog/2017/09/asmjs_emscripten.html asm.js 和 Emscripten 入门教程 作者: 阮一峰 日期: ...
- Jquery 官网下载流程
选中解压版本,然后把ctrl+s保存另存为他的min版本
- React Native踩坑之Unable to load script from assets
报错: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged corr ...
- Contains,Exists,Any,Count 比较是否存在某个元素
private static void Main(string[] args) { ; Console.WriteLine("判断是否存在某个元素 :"); Console.Wri ...
- c++源文件后缀名问题
VC里用cpp作后缀名, 在GCC里默认采用C.cc.cxx作为后缀名 .cpp, .h (VS file).cc, .h (GCC file) C中: 头文件后缀名: .h 源文件后缀名: .c ...
- 【UOJ #105】【APIO2014】Beads and wires
http://uoj.ac/problem/105 好神的dp啊. 确定一个点为根之后,蓝线只能是竖着的,不能横跨兄弟. 枚举每个点为根进行树形dp是\(O(n^2)\)的,\(f(x,0/1)\)表 ...
- RE:从零开始的AGC被虐(到)生活(不能自理)
RE:从零开始的AGC被虐(到)生活(不能自理) 「一直注视着你,似近似远,总是触碰不到.」 --来自风平浪静的明天 AtCoder Grand Contest 001 B: Mysterious L ...
- 【二项式定理】【DFS】UVALive - 7639 - Extreme XOR Sum
题意:一个序列,q次询问,每次问你某个指定区间内的EXtreme XOR值. 一个长度为l的区间的EXtreme XOR值被定义为,从左到右,将每相邻的两个数XOR起来,产生l-1个新的值,……如此循 ...