Author: 芳草苑主

  • Create a password file for Nginx basic authentication

    It is really a hard time for me to find a way to create a password file for Nginx basic authentication, because I did not realise htpasswd crpty is not available on Windows.

    Nginx documentation only mentions Use crypt(3) encryption for passwords, so I tried so hard with htpasswd.exe but could not generate a file recognised by Nginx. Hours later I found Apache documentation mentions -d is

    the default on all platforms but Windows, Netware and TPF. Though possibly supported by htpasswd on all platforms, it is not supported by the httpd server on Windows, Netware and TPF.

    I have two things to blame –

    1. I still use Windows to do my everyday work. If my first choice was htpasswd on Linux even without furthur instructions, it would have save me a lot of time.
    2. Nginx documentionation. If Nginx documentation is as good as Apache’s, Nginx may overwhelm the world.
  • Magento Skip Base URL validation before next step

    终于明白 Magento 在安装时问的一个问题是什么意思了:

    Skip Base URL validation before next step

    Check this box only if it is not possible to automatically validate Base URL. 

    如果给 Magento 指定一个 Base Url 在 internet 上不可解析,比如在开发阶段使用一个 Base Url 只在本机或内网内访问,则必须跳过 Base Url validation。

  • Perfect settings for Magento on Nginx

    Nginx 的文档不够详细,挺折腾人的。我经过两天181次黑匣试验,终于敢说入了 Nginx 的门。摸清 Nginx 的思路以后,才体会到它的先进性(不仅是效率上的)。php 和 nginx 搭配使用,感觉就不那么草根了,更容易借鉴 python 的 web infrastructure.

    从 Apache 到 Ngnix,不容易啊。难就难在要抛弃 Apache 的思维,其实同样的配置在 Nginx 总能做到的,而且更简洁。在Apache 下,我用 symbolic link 实现 Magento 和 WordPress 等一次安装多处使用,当时我认为已经是很简单的解决方案了;转移到 Nginx 平台,多处使用连 symblic link 也省了。

    以下是 Magento on Nginx 的配置,perfect,可以以不变应万变,目前我挺得意的。别笑我,这么几行配置,折腾我两天。

    location / {
    
    root  $php_doc_root;
    
    index  index.php;
    
    if ($uri ~ ^/(media|js|skin)/) {
    
    break;
    
    }
    
    if (!-e $request_filename) {
    
    rewrite .* /index.php last;
    
    }
    
    }
    
    location ~ ^/(app|lib|var)/ {
    
    deny all;
    
    }
    
    location ~ ^/report/.*\.xml {
    
    deny all;
    
    }
    
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ {
    
    root  $php_doc_root;
    
    index  index.php;
    
    access_log        off;
    
    expires           30d;
    
    }
    
  • Bkf is not found is not true

    When I tried to restore from bkf file created by Windows in-built System Tool Backup and Restore, I was not aware another colleague was accessing (read access) this file. At the last page of Restore wizard, it threw an error with a nonsense error message – “(the file name).bkf Disk 1 is not found”. The error message scared me because this bkf file is my only backup file I have. I do not have any other file like Disk 1, Disk 2. If this file is corrupted, nothing else I can fallback.

    I was released when I retried after my colleague finishing reading the file. Everything successfully restored when I had exclusive access to the bkf file.

    我早该想到 Windows 的错误提示往往不是它字面的意思。

    早就想用 Linux 的备份工具,但是很惭愧,还没熟练掌握,所以重要的备份还是在 Windows 下完成。

  • My understanding to Nginx so far

    Location directive 没有fallback 机制。因为一个 request 只能匹配一个 location,不是常规 location 的话,就是正则表达式 location。假如有两个 location blocks,
    location / {
    index index.php;
    }

    location /abc {
    client_max_body_size 32m;
    }

    请别指望 index index.php  会在location /abc 生效。因为这是两个 location,只能有一个生效,另一个被忽略。

    正则表达式 location 优先于常规 location 匹配(除非常规 location 使用 ^~ 或 =);常规 location 之间最长匹配优先;正则表达式 location 之间位置在前优先。

    Nginx wiki 文档里关于 location 用到的 “searching stops” 这个词很不恰当,挺误导初学者的思维,让人误以为会有两个或两个以上 location同时生效。

    正则表达式 location 以 ~ 或 ~* 开头,其他的都是常规 location (以 ^~ 开头的貌似正则表达式 location,却是常规 location)。

    Root directive 和 alias directive 用处类似,只是 alias 不改变 document root。但是,它们对文件的定位方式明显不同。例:
    如配置文件使用 root –
    server {
    server_name _;
    root /default/path;

    location /abc {
    root /another/path;
    }
    }
    Request to /abc/filename.jpg 将对应 /anther/path/abc/filename.jpg。
    如配置文件使用 alias –
    server {
    server_name _;
    root /default/path;

    location /abc {
    alias /another/path;
    }
    }
    Request to /abc/filename.jpg 将对应 /anther/path/filename.jpg。

    以上是我用我的语言的去理解 Nginx 的语法。

  • Different syntax in Nginx and Apache

    今天发现一个 Nginx 和 Apache 看似细微却影响巨大的语法差异:

    在 Apache 里重定向一个域名到另一个域名,

    RewriteRule (.*) http://destination.com/$1 [r=301,l]

    而在 Nginx 里,应该多加一个斜杠/,否则 $1就多了一个斜杠。

    rewrite ^/(.*) http://destination.com/$1 permanent;

  • Zend_Db ignore default charset of Mysql

    While I set my Mysql database default character set as UTF-8, Zend_Db_Adapter does not pick up the setting. Zend_Db write to Mysql using its own default character set (I guess it’s ISO-8859-1), unless it is specifically told by

    $dbAdapter->query(“SET NAMES ‘utf8′”);

    before

    Zend_Db_Table::setDefaultAdapter($dbAdapter);

  • Resin and chrome

    我发现 Resin (Web Server) 和 Chrome (Browser) 竟然使用相同的 Widows 任务栏图标。Is Resin project sponsored by Google? Is GWS (Google Web Server) based on Resin? It’s just my guess. Resin does not say anything about Google on its site.

    When I tried to search the relationship between Resin and Chrome, I found Resin and Chrome is a kind of storage basket. But it’s difficult to describe resin and chrome in Chinese – 带支架的藤条箱? Maybe.

    resin chrome
    resin chrome

    However, if you search Resin and Chrome in Google Image Search, nothing like 带支架的藤条箱 show up in first 2 pages. So, what is Resin and Chrome?

    resin chrome google image search result
    resin chrome google image search result
  • Bonjour is not virus

    Bonjour bundled with Sarifi
    Bonjour bundled with Sarifi

    不知道 Bonjour 是怎么进入到我的电脑的,我不用Sarifi已经好多年。我不喜欢Apple的东西,装Sarifi只是为了测试,测试完毕重装系统也没再想着把Sarifi装回来。

    第一次注意到 Bonjour 进程的存在着实让我担心了一把,还以为是什么病毒,Google 了一下才知道是 Apple 开发的一个玩意儿才打消了我的顾虑。今天我再次安装Sarifi,里面提到 Bonjour,因为事先跟 Bonjour 有过接触,所以注意到了,拷屏下来告诉初识 Bonjour 的人,Bonjour 是无害的(但我也没意识到 Bonjour 有什么好处)。

  • Run Magento on GAE

    Google App Engine 不久前开始支持第二种语言 Java,我当时听到这个消息马上开始期盼什么时候 GAE 支持 PHP。

    今天看到 Quercus 项目,它可以让 PHP 运行在 Java 环境,我才意识到不用再期盼在 GAE 跑 PHP 程序,这已成为现实。这下我有事情做了——怎么把 Magento 跑在 GAE 上?