有关nginx的一些总结
首先看一下一般nginx管理的一些命令1
2
3
4
5
6
7
8
9
10
11
12
13sudo apt-get install nginx
sudo /etc/init.d/nginx start #通过init.d下的启动文件启动
sudo service nginx start #通过ubuntu的服务管理器启动
ps -ef | grep nginx //查看nginx的进程
ps aux|grep nginx
kill -QUIT 主进程号 //关闭进程
/etc/init.d/nginx start //启动nginx
kill -INT master //关闭nginx
备份日志文件
mv log log2; //备份一个文件
Kill -USR1 `cat /xxx/path/log/nginx.pid`
nginx配置的一些意义
1 | worker_processes 1; // 有1个工作的子进程,可以自行修改,但太大无益,因为要争夺CPU,一般设置为 CPU数*核数 |
基于端口的虚拟主机配置1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
error_log /home/wwwlogs/nginx_error.log crit; //crit错误信息最少 debug错误信息最多 debug, info, notice, warn, error, crit
server {
listen 80; #监听端口
server_name a.com; #监听域名
location / {
root /var/www/a.com; #根目录定位
index index.html;
}
#正则表达式的localtion会覆盖掉 / 的匹配,所以图片会直接访问图片
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
root /home/www/var/www/image;
expires 30d;
}
}
response headers
Transfer-Encoding:chunked //内容是分块传输的
http 304 notModifed 文件还没有过期呢;nginx expires 30d;
1 | location ~ [^/]\.php(/|$) |
./configure –prefix=/usr/local/fastphp –enable-fpm –with-mcrypt –enable-mbstring –disable-pdo –with-curl –disable-debug –disable-rpath –enable-inline-optimization –with-bz2 –with-zlib –enable-sockets –enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex –with-mhash –enable-zip –with-pcre-regex –with-mysql –with-mysqli –with-gd –with-jpeg-dir