我爱linux

我是一个linux运维从业者,这个网站记录一些平时调试linux相关文档及生活随笔

Archive for the ‘nginx’ tag

nginx编译错误解决

without comments

准备在我的debian 5上把nginx的升级到最新版,默认的版本实在有点老,但在编译过程中发现如下错误

 

./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module
 
make
然后出现如下错误:
 
make -f objs/Makefile
make[1]: Entering directory `/root/tmp/nginx-1.0.8'
cd /usr \
        && if [ -f Makefile ]; then make distclean; fi \
        && CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure –disable-shared
/bin/sh: line 2: ./configure: No such file or directory
make[1]: *** [/usr/Makefile] Error 127
make[1]: Leaving directory `/root/tmp/nginx-1.0.8'
make: *** [build] Error 2
 
解决方法:
安装libpcre3-dev就行
apt-get install libpcre3-dev
 
然后再次编译没问题了

Written by zhangweibo

十二月 4th, 2011 at 4:25 下午

Posted in nginx

Tagged with ,

nginx的访问日志log用logrotate来做日志轮询

without comments

在vps上做网站,切记做好日志的轮询工作,如果你的访问量比较大的,如果不进行好的处理,长期积累,日志会撑爆你的vps空间容量,嘿嘿,本身我们的空间容量就有限。

早些年,都是用cronolog来做日志轮询,不过这个是为了方便在自己的服务器上统计访问速度,后来随着网站的访问量越来越大,发现站点统计比较耗费系统资源,所以索性都交给了google或者百度进行网站统计,毕竟他们都是实时统计。

ok,那我们就用最简单的方法做一下nginx的日志轮询处理,哈哈,我就是个大懒人,能简单处理,绝不复杂化

默认logrotate其实已经对nginx做了轮询处理,只不过默认配置也会占用不少空间,如果你的小站访问量不大,那问题不大,如果访问量中等,建议把配置稍微改一下

/var/log/nginx/*.log {
daily
missingok
rotate 3
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
endscript
}

默认rotate 是52 有点太多了,天哪,得占用多少空间,我直接改成7,转存储7个文件就够了
然后默认是每天处理,我觉得不用改了

修改好以后,让新的配置生效
logrotate -f /etc/logrotate.conf

好了,vps爱好者们,基本你们不用愁日志会占满你们的空间了。

Written by zhangweibo

十二月 3rd, 2011 at 6:24 上午

Posted in nginx

Tagged with , ,

在nginx服务器上配置shopex的rewrite静态化重写规则

without comments

如果你的shopex建立在nginx服务器上,那rewrite重写规则如下,很简单的3行

 

if (!-e $request_filename) {
rewrite ^(.*)/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ $1/index.php?$2 last;
}
大概意思,就是所有的访问链接都统一扔给index.php去处理静态化

Written by zhangweibo

十二月 2nd, 2011 at 2:42 下午

Posted in nginx,shopex

Tagged with , ,

Debian 6(Squeeze)安装 Nginx + PHP5 + Spawn-fcgi + MySQL(二)

without comments

之前,给大家讲了Debian 6(Squeeze)安装 Nginx + PHP5 + PHP-FPM + MySQL(一),但因为要修改源,所以可能有些同学不大愿意,这里我们讲一下不修改源的情况下,怎么实现nginx的php环境

1:安装 MySQL 5

apt-get install mysql-server mysql-client

在弹出的页面输入2次密码

修改mysql配置文件,去掉innodb,这样可以节省不少内存
vi /etc/mysql/my.cnf

增加下面语句
skip-innodb

保存后,mysql重启一下就生效

2:安装Nginx + PHP5

apt-get install php5-cgi php5-mysql php5-gd php5-imagick php5-mcrypt php5-memcache memcached nginx

安装成功后,rcconf 把多余的服务x11-common去掉

mkdir /var/www
chown www-data:www-data /var/www

修改memcache的端口和内存大小
vi /etc/memcached.conf

vi /etc/php5/cgi/php.ini
修改下面这句
cgi.fix_pathinfo=1

3:安装Spawn-fcgi
Spawn-fcgi和php-fpm都能很好的实现nginx的php环境,其实对一些小规模的网站来说,Spawn-fcgi也是能很好的工作的,不见得非要php-fpm。

apt-get install spawn-fcgi

4:配置spawn-fcgi
系统启动的时候,自动加载spawn-fcgi
vi /etc/rc.local
增加下面语句
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid -C 4

这个我们是用了 -c 4 代表启动4个php5-cgi进程,大家可以根据自己的需要启动相应的进程数,我的256M的vps,我默认启用3-4个就能满足要求了。

5:配置nginx:
修改nginx的配置文件
vi /etc/nginx/nginx.conf
修改以下字段
worker_processes 4;
在我256M的vps上,我修改成4-6个,满足一般网站的访问绰绰有余

接着
vi /etc/nginx/sites-available/default

添加:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}

保存后,重启nginx
/etc/init.d/nginx restart
写一个测试php页面

如果能正常显示那页面,那就大功告成

Written by zhangweibo

四月 24th, 2011 at 3:34 下午

Posted in debian,nginx,Php

Tagged with , , , , ,