nginx
2016-04-01 23:27
666 查看
nginx的信号控制
ITEM,INT
Quick shutdown
QUIT
Graceful shutdown 优雅的关闭进程,即等请求结束后再关闭
HUP
Configuration reload ,Start the new worker processes with
a new configuration Gracefully shutdown the old worker processes
改变配置文件,平滑的重读配置文件
USR1
Reopen the log files 重读日志,在日志按月/日分割时有用
USR2
Upgrade Executable on the fly 平滑的升级
WINCH
Gracefully shutdown the worker processes 优雅关闭旧的进程(配合USR2来进行升级)
nginx配置段
日志轮替
location
rewrite
nginx+php的编译
gzip配置常用参数
反向代理
负载均衡
server {}
server {}
upstream servername{
server 192.168.1.1:81 weight=1 max_fails=2 fail_timeout=3;
server 192.168.1.1:82 weight=1 max_fails=2 fail_timeout=3;
}
location ~* .(jpg|jpeg|gif|png){
proxy_pass http://servername;
}
memcache
ITEM,INT
Quick shutdown
QUIT
Graceful shutdown 优雅的关闭进程,即等请求结束后再关闭
HUP
Configuration reload ,Start the new worker processes with
a new configuration Gracefully shutdown the old worker processes
改变配置文件,平滑的重读配置文件
USR1
Reopen the log files 重读日志,在日志按月/日分割时有用
USR2
Upgrade Executable on the fly 平滑的升级
WINCH
Gracefully shutdown the worker processes 优雅关闭旧的进程(配合USR2来进行升级)
nginx配置段
//全局区 work_processes 1; //有一个工作的子进程,一般设置为CPU数*核数 Event{ //配置nginx连接特性 work_connections 1024; //一个子进程最大允许1024个连接 } http{ server{ //虚拟主机段 listen 80; //监听端口 server_name a.com; //监听域名 location{ root html; //根目录定位 index index.html; } } }
日志轮替
#!/bin/bash LOGPATH =/usr/local/nginx/logs/access.log BASEPATH=/usr/local/nginx/data/$(date -d yesterday +%Y%m) mkdir -p $(BASEPATH) bak=$BASEPATH/$(date -d yesterday +%d%H%M).access.log mv $LOGPATH $bak touch $LOGPATH kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
location
location =/ //精准匹配 location / //普通匹配 location ~ //正则匹配
rewrite
location /ecshop { index index.php; rewrite goods-([\d]+)\.html$ /ecshop/goods.php?id=$1; rewrite article-([\d]+)\.html$ /ecshop/article.php?id=$1; rewrite category-(\d+)-b(\d+)\.html /ecshop/category.php?id=$1&brand=$2; // 注意:用url重写时, 正则里如果有”{}”,正则要用双引号包起来 }
nginx+php的编译
// apache一般是把php当做自己的一个模块来启动的. //而nginx则是把http请求变量(如get,user_agent等)转发给 php进程,即php独立进程,与nginx进行通信. 称为 fastcgi运行方式 //注意: 我们编译的PHP 要有如下功能: //连接mysql, gd, ttf, 以fpm(fascgi)方式运行 ./configure --prefix=/usr/local/fastphp \ --with-mysql=mysqlnd \ --enable-mysqlnd \ --with-gd \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --enable-fpm cp /usr/local/src/php/php.ini-development ./lib/php.ini cp etc/php-fpm.conf.default etc/php-fpm.conf
gzip配置常用参数
gzip on|off // gzip_buffers 32 4K | 16 8K //缓冲(压缩在内存中缓冲几块? 每块多大?) gzip_comp_level[1-9] //级别越高,压的越小,越浪费CPU计算资源 gzip_disable //正则匹配UA 什么样的Uri不进行gzip gzip_min_length 200 // 开始压缩的最小长度(再小就不要压缩了) gzip_http_version 1.0|1.1 //开始压缩的http协议版本 gzip_proxied //设置请求者代理服务器,该如何缓存内容 gzip_types text/plain application/xml //对哪些类型的文件用压缩 如txt,xml,html ,css gzip_vary on|off //是否传输gzip压缩标志
反向代理
location ~ \.php${ proxy_set_header X-Forwarded-For $remote_addr proxy_pass http://192.168.1.1:8080;//把请求的PHP文件代理到Apache服务器。 //修改httpd.conf。allowoverride all引入extra/httpd-vhosts.conf //修改extra/httpd-vhosts.conf。指定根目录,服务器名,端口 }
负载均衡
server {}
server {}
upstream servername{
server 192.168.1.1:81 weight=1 max_fails=2 fail_timeout=3;
server 192.168.1.1:82 weight=1 max_fails=2 fail_timeout=3;
}
location ~* .(jpg|jpeg|gif|png){
proxy_pass http://servername;
}
memcache
//安装memcache扩展 cd memcache /usr/local/php/bin/phpize ./configure --wit-hphp-config=/usr/local/php/bin/php-config make && make install //把扩展添加到php.ini里 vim /usr/local/php/lib/php.ini extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/memcache.so //重启PHP location \ { set $memcached_key "$uri"; memcached_pass 127.0.0.1:11211; error_page 404 /callback.php; }
相关文章推荐
- PHP和Nginx 文件上传大小限制问题解决方法
- nginx的sbin和conf文件不在同一目录怎么装安全狗
- 编译安装nginx及简单优化配置
- Nginx启用Gzip压缩js无效的原因
- 开启Nginx的gzip压缩功能详解
- keepalived对nginx高可用演练脚本
- CentOS7搭建OpenResty Nginx
- 使用Nginx+Unicorn+Capistrano+Sinatra搭建Ruby Web应用
- Ubuntu编译安装PHP和Nginx
- 页面跨域传参 nginx iframe
- linux centos6.7安装nginx1.6 php5.6.15
- nginx基本配置
- nginx虚拟主机的配置
- CentOS 6.4 x86_64 部署 nginx 服务器实现点播功能
- 记一次 nginx 504 Gateway Time-out
- 简单配置nginx使之支持pathinfo
- nginx中配置跨域支持功能
- nginx [alert] 12339#0: 1024 worker_connections are not enough
- 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序
- ubuntu 14.04 编译安装 nginx