Month: June 2009

  • Difference of try_files to rewrite in Nginx

    try_files 是 Nginx 自0.6.36 新增的 directive。通常对 try_files 的理解是——它是
    if (!-e $request_filename) {
    rewrite .* /index.php;
    }

    的更简洁的表达。但我发现它们之间还是略有区别,主要表现在两点:

    1. 如使用 rewrite,Nginx 要求 document_root 下必须有一个 index 文件,即使我把另一个目录别名整个 document_root,但因为 Nginx 先校验 document_root 下是否有一个 index 文件,所以得放置一个空 index 文件。try_files 则没有 index 文件校验,直接去第二、第三… document_root 找对应的文件。
    2. 如使用 try_files $uri $uri/ /index.php,index.php 不能取得 get 变量,例如在 Magento 下,对 http://mydomain/catalogname?mode=list 的访问不能起效,Nginx 交付的页面是 http://mydomain/catalogname。这时必须使用 rewrite。这或许是 try_files 的一个 bug。
  • Nice looking wqy fonts

    装 Fedora 时我选 locale 是 United Kingdom,所以中文字体没有装。但能读中文,也能输入中文,大概得感谢 utf-8 之类的标准。

    但英文 Fedora 显示中文的方式太别扭了,一句话里会夹杂几个字黑体,几个字宋体。我不理解为什么会这样,不研究了,用
    yum install wqy*

    把文泉驿字体装上就好看多了。

  • Linux talks to Linux using Windows languages

    MyBook World Edition 基于 Linux,却是面向 Windows 用户的产品。Linux 用户怎么访问它?我一时犯傻了。

    因为我早就破解了我的 MyBook World 的根密码,所以我首先想着用 root 身份、sftp 方式去访问 MyBook World。但是 Windows 用户上载到 MyBook World 的文件所有者是 www-data, root 上载上去的文件 www-data 不可写。我无从得知 www-data 的初始密码,否则我就用 www-data 身份、sftp 方式去访问 MyBook World。如果我强行修改 www-data 初始密码,万一把 MyBook World 搞瘫痪了,一个 network drive 只能当 external drive 用就不值了。

    好长时间以后才想到,Fedora 自带 Connect to server -> Windows share 就可以 samba client 去访问 MyBook World。Samba 本来就是为 Windows 和 Linux 之间的通讯开发的,但现在两台 Linux 的机器,因为要照顾到其他 Windows 用户,所以只能用 Samba 来对话。

    不管怎么说,问题解决了。只留下一个小小的问题—— Windows 下,\\ip address or netbios name 就可以看到所有的共享文件夹,在 Fedora 的 Connect to server -> Windows share 则必须把共享文件夹作为 share 的名字输入后才能连接,如果只输入 ip address or netbios name 则出现 Cannot display location “smb://ip address or netbios name/” ,no application is registered as handling this file. 那怎么查看所有共享文件夹?

  • Finetune 1and1 dedicated server with CentOS

    Although the start with 1&1 was not pleasant, I decided to stay with 1&1 and upgraded from a VPS to a dedicated server. (sadly, this VPS performance is much better than the dedicated server I got.) Now it is time to finetune it. The server came with CentOS, which is not my favourite, but it the best OS I can choose from the list.

    The first thing to do is

    yum update

    I am using Ngnix instead of Apache, so turn off pre-installed Apache. Better to do it as the first thing, as I did not aware that httpd is running which prevented nginx from starting and wasted a lot of time to find the reason.
    service httpd stop
    chkconfig --level 235 httpd off

    CentOS depository is missing lots of packages. I add two 3rd party repositories, epel (to get Nignx) and remi (to get the newest php 5.2.9).
    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-3.noarch.rpm
    rpm -Uvh http://rpms.famillecollet.com/enterprise/5/remi/x86_64/remi-release-5-7.el5.remi.noarch.rpm

    Because I use try_files directive quite often in nginx conf files, but try_files starts from nginx 0.6.36, I can not use nginx 0.6.35 in epel repository. Luckly, epel-testing repository has nginx 0.6.36.
    yum install nginx --enablerepo=epel-testing

    The following commands are straight-forward.
    yum install memcached
    chkconfig --level 235 memcached on

    yum install php-pecl-apc
    yum install phpMyAdmin
    yum install spawn-fcgi

    I encounted difficulty install vim. First try is using yum install vim. It works on other CentOS I installed, aslo works with CentOS on 1&1 VPS, but just does not work on this 1&1 dedicated server. I do not know why. Nevertheless, the below listed command works.
    yum install vim-enhanced

    Because magento requires php 5.2.0 or above, but CentOS current php version is 5.1.6, it must be updated.
    yum update php --enablerepo=remi

    I saw some file conflicts from some mysql packages. To solve this problem,
    cd /var/cache/yum/remi/packages
    rpm -Uvh --force mysql<tab>

    <tab> will automatically fill in the package file name.

    mysql was up and running, but 1&1 did not tell me how to log into it. It took me a couple of hours to try different combinations of possible usernames and passwords before I gave up. Then I stopped mysqld, restarted it with
    mysqld_safe --skip-grant-tables

    Then I could go to user table in mysql database to reset root password. However, I found root as a username was not there. Instead, it is admin with all privileges.

    So, I quitted mysql, restarted it in a normal way, tried to put in admin as username and the same password as server root user, it worked!

    I changed the owner of php session directory (/var/lib/php/session) from apache to nginx, otherwise php could not start session without errors.

    I expected the server would work by now, but it did not. It took me another hour to find out it was because php.ini of 1&1 dedicated server had
    safe_mode default on

    Just turn safe_mode off, because I do not need it. Now my lovely server is fully up.

  • Varnish vs Nginx

    Fedora 10 release note 提及 Varnish,据说“Varnish 是一个高性能 HTTP 加速器”,又看了一些其他网站的介绍,据说比 squid 快了好几倍。squid 是什么?没听说过。但既然同是反向代理服务器,Varnish 和 Nginx 相比如何?

    我没实测,但引用别人的测试结论:

    • 根据 Connection Times 获知 Varnish 连接速度快于 Nginx,但 Nginx 处理速度快于 Varnish,等待时间几乎一致,总时间 Nginx 要快于 Varnish 15%左右。
    • 根据 HTML transferred 项获知大负载下 Varnish存在较多的丢包问题。

    我想我还是坚持走 Nginx,并走好它。

  • recordset.clone is not working

    我修改了一段以前写的 vba,用到了 recordset.clone,没想到由于 vba 本身的 bug,克隆并没有进行,recordset.clone 返回值仍然是原记录集的引用。我在返回值记录集进行了 recordset.delete,结果把我原本想保持不动的原记录集里的记录给删了。

    那个恨啊!实在没想到 recordset.clone 只引用不克隆,害我为恢复原记录折腾了很久。我没兴趣深究原因,就当是 vba bug,就算是我调用参数配置不当,recordset.clone 克隆不成功也不能随随便便返回一个值而不抛出错误。

    既然 recordset.clone 不能用,找了一个前辈 Robert Gelb 写的函数来做真正的克隆。

    Public Function Clone(ByVal oRs As ADODB.Recordset, _
        Optional ByVal LockType As ADODB.LockTypeEnum = adLockUnspecified) As ADODB.Recordset
    
        Dim oStream As ADODB.Stream
        Dim oRsClone As ADODB.Recordset
    
        'save the recordset to the stream object
        Set oStream = New ADODB.Stream
        oRs.Save oStream
    
        'and now open the stream object into a new recordset
        Set oRsClone = New ADODB.Recordset
        oRsClone.Open oStream, , , LockType
    
        'return the cloned recordset
        Set Clone = oRsClone
    
        'release the reference
        Set oRsClone = Nothing
    End Function
    
  • Goodbye, Windows

    在个人桌面应用领域,我也早就想跟 Windows 说 byebye,但一直懒于重装系统。

    最近换了台 64位的服务器,虽然硬件指标跟原来的比较,除了 32位升级到64位,其他方面并未有太多提升,但性能却强劲不少。既然服务器的性能能有这么大的提升,为什么不把我的桌面也提升一下?一直埋没了64位的 CPU 两年多,突然很想见识一下它在 64位操作系统下的表现。

    于是下载了 Fedora x86_64,擦除了厂商的出厂分区,一键恢复 Windows 也没了,彻底投入 Linux 怀抱。

  • Yum update php to 5.2.x on CentOS

    The current php version with CentOS is 5.1.6. Even epel repository’s php is 5.1.6. I am disappointed with epel slow up-to-date, but I found three 3rd party repositories to update php. Installation of these repositories are slightly diffferent.

    • remi repo has php 5.2.9. To install, just run

      rpm -Uvh http://rpms.famillecollet.com/enterprise/5/remi/x86_64/remi-release-5-7.el5.remi.noarch.rpm

    • atomic repo has php 5.2.9. To install, download this script and run it

      wget http://www.atomicorp.com/installers/atomic.sh

    • james’ utterramblings repo has php 5.2.6. To install, import GPG key first

      rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

      create a repo file manually with the following content

      [utterramblings]
      name=Jason's Utter Ramblings Repo
      baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
      enabled=1
      gpgcheck=1
      gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka