nginx常用配置

server {
    listen 80;
    server_name afreelyrics.com www.afreelyrics.com;
    #host跳转到主域名
    if ($host != "afreelyrics.com") {
        rewrite ^(.*) http://afreelyrics.com$1 permanent;
    }
    access_log /var/log/nginx/afreelyrics.com/access.log;
    error_log /var/log/nginx/afreelyrics.com/error.log;
    root /srv/www_root/afreelyrics.com/web;

    #优先读取static目录下的静态页
    if (-f "${document_root}/static${uri}") {
        rewrite ^/(.*)$ /static/$uri break;
    }

    #lyrics detail,must befor artist detail
    rewrite ^/([^/]+)/([^/]+)\.html$ /index.php/lyrics/lyrics/$1/$2 break;

    #artist detail
    rewrite ^/([^/]+)\.html$ /index.php/artist/artist/$1 break;

    #search
    rewrite ^/s/([^/]*)/?$  /index.php/search/index/$1 break;
    rewrite ^/s-lyrics/([^/]+)(/|/(\d+)\.html?)?$ /index.php/search/lyrics/$1/$3 break;
    rewrite ^/s-artist/([^/]+)(/|/(\d+)\.html?)?$ /index.php/search/artist/$1/$3 break;

    #php
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php/$1 break;
    }

    location ~* \.(js|css|gif|jpeg|jpg|png|ico|bmp)$ {
        expires 3d;
        break;
    }
	
    include /etc/nginx/php.conf;
}

server {
    listen 80;
    server_name *.afreelyrics.com;
    return 404;
}

#php.conf
location ~* \.php($|/) {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    fastcgi_param SERVER_NAME       $server_name;
    fastcgi_param PATH_INFO         $fastcgi_script_name;
}

 

Cron 导致的乱码问题

cron 会使用一个最小化的环境来执行任务。

可以用 cron 来执行一下 env 来验证这一点:
*/1 * * * * /usr/bin/env > /tmp/cronenv
在我的机器(Gentoo 64位,vixie-cron)上输出的结果是这样的:
[~]$ cat /tmp/cronenv
SHELL=/bin/sh
USER=jerry
PATH=/usr/bin:/bin
PWD=/home/jerry
SHLVL=1
HOME=/home/jerry
LOGNAME=jerry
_=/usr/bin/env

继续阅读

编译PHP configure: error: Cannot find libmysqlclient under /usr

是因为configure中lib目录不对导致,64位系统中libmysqlclient.so位于/usr/lib64/mysql中,编译configure文件,找到libmysqlclient,for循环中加上lib64/mysql即可,结果如下:

  for i in lib lib/mysql lib64/mysql; do

  str="$MYSQL_DIR/$i/libmysqlclient.*"
  for j in `echo $str`; do
    if test -r $j; then
      MYSQL_LIB_DIR=$MYSQL_DIR/$i
      break 2
    fi
  done

  done