nginx
来源:互联网 发布:mysql中union的用法 编辑:程序博客网 时间:2024/05/13 13:52
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配置段
//全局区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/bashLOGPATH =/usr/local/nginx/logs/access.logBASEPATH=/usr/local/nginx/data/$(date -d yesterday +%Y%m)mkdir -p $(BASEPATH)bak=$BASEPATH/$(date -d yesterday +%d%H%M).access.logmv $LOGPATH $baktouch $LOGPATHkill -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-fpmcp /usr/local/src/php/php.ini-development ./lib/php.inicp 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不进行gzipgzip_min_length 200 // 开始压缩的最小长度(再小就不要压缩了)gzip_http_version 1.0|1.1 //开始压缩的http协议版本gzip_proxied //设置请求者代理服务器,该如何缓存内容gzip_types text/plain application/xml //对哪些类型的文件用压缩 如txt,xml,html ,cssgzip_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.iniextension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/memcache.so//重启PHPlocation \ { set $memcached_key "$uri"; memcached_pass 127.0.0.1:11211; error_page 404 /callback.php;}
0 0
- nginx
- Nginx
- Nginx
- Nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- 阶梯博弈(Stair Nim)
- bzoj2744【HEOI2012】朋友圈
- 使用optparse模块来解析命令行参数
- thinkphp
- bzoj2194 快速傅立叶之二
- nginx
- iOS9如何调用系统通讯录
- SQL中的约束语句
- linux下socket通信,server和client简单例子
- bzoj3527【ZJOI2014】力
- 第十一章:正则表达式
- bzoj3992【SDOI2015】序列统计
- 洛谷 1855 榨取kkksc03
- POJ 2253 Dijstra 最短路变形