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 ...
随机推荐
- ubuntu安装Shutter截图工具以及设置系统快捷键
一.安装截图工具 Shutter 1. 添加安装包软件源 sudo add-apt-repository ppa:shutter/ppa 2. 更新源并安装 shutter sudo apt-get ...
- Solr本地服务器搭建及查询
0.安装solr之前,确保已安装好java8, java -version 查看是否安装 1.新建本地目录solr1 并 解压两个压缩包文件 .tar.gz .tgz tomcat7 2.将CATA ...
- rsync: chroot No such file or directory (2)
rsync: ) 查了N多资料,均未解决,最终发现是因为report后面多了个空格...
- Windows 10家庭版远程桌面连接错误
由于需要操作远程服务器,经常使用“远程桌面连接”工具,一直很正常.今天突然提示 出现身份验证错误,可能是由于 CredSSP加密Oracle修正.什么情况!! 根据提示的地址https://go.mi ...
- javax.persistence.EntityNotFoundException: Unable to find报错
这类错id 可能是10,可能是27,也可能是其他数字 错误描述: javax.persistence.EntityNotFoundException: Unable to find 某个类 with ...
- Python编程举例-装饰器
装饰器的通常用途是扩展已定义好的函数的功能 一个浅显的装饰器编程例子 #装饰器函数 def outer(fun): def wrapper(): #添加新的功能 print('验证') fun() r ...
- 【BZOJ 2555】 2555: SubString (SAM+LCT)
2555: SubString Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 2548 Solved: 762 Description 懒得写背景了 ...
- 【BZOJ 3561】 3561: DZY Loves Math VI (莫比乌斯,均摊log)
3561: DZY Loves Math VI Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 205 Solved: 141 Description ...
- BZOJ [JSOI2008]星球大战starwar
正着显然不可做,我们采取反向并查集,将删点改为加点,每次贪心的认为加了一个联通块,一旦不符就减一. #include<bits/stdc++.h> using namespace std; ...
- UVA11019 Martix Matcher --- AC自动机
UVA11019 Martix Matcher 题目描述: 给定一个\(n*m\)的文本串 问一个\(x*y\)的模式串出现的次数 AC自动机的奇妙使用 将\(x*y\)的模式串拆分成x个串,当x个串 ...