Typecho 在 Hiawatha web server 上的伪静态写法 

现在很多的人从Wordpress 转到了Typecho,从Apache httpd 转到了 Nginx.不得不说,typecho + nginx 是一个比较流行的博客搭配~

可是,使用除nginx外的其他用户就成了缺少支持的群体了,就拿typecho 来讲,它的官方doc(http://docs.typecho.org/servers)里面就没有提到除nginx 外的其他web server,连apache 也是轻描淡写的带过了。

那么,lighttpd 肿么办?hiawatha 肿么办?cherokee 肿么办?

没办法,只能用户自己搞定。

我就是一名typecho + hiawatha 的用户,一直以来,我的伪静态就不太理想,前台还行,后台很坑爹,基本属于不能用。

这是typecho 给出的适用于nginx的伪静态:

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

location ~ .*\.php(\/.*)*$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}


我之前照着写过一个给hiawatha用,不是很完美~见下:

UrlToolkit {
ToolkitID = te
RequestURI exists Return
Match ^.*$ Rewrite /index.php$1
}


一直想把这个问题修复,今天在逛hiawatha的在线手册(http://www.hiawatha-webserver.org/manpages)的时候,无意发现了EnablePathInfo 标签,见下:

EnablePathInfo = yes|no
Accepts URLs like /index.php/parameter if /index.php exists and the extension .php has been configured as a CGI program. '/parameter' will be placed in the environment variable PATH_INFO.
Default = no, example: EnablePathInfo = yes


我忽然明白了hiawatha 和 nginx 的不同之处~火速编辑我的hiawatha配置文件,改成如下:

VirtualHost {
Hostname = xiazhengxin.name,blog.xiazhengxin.name
WebsiteRoot = /home/http/blog_xiazhengxin_name
StartFile = index.php
UseFastCGI = PHP4TE
UseToolkit = te
ShowIndex = yes
FollowSymlinks = yes
EnablePathInfo = yes #加了这一行
# AccessList = allow 127.0.0.1,deny all
}


即启用PHP 的PathInfo功能。果然,重启hiawatha,伪静态完美了~
[ ] ( 3487 次浏览 ) 永久链接 ( 3 / 2680 )
修复Ubuntu Natty 64位 在DELL OptiPlex 790 机器上无法重启的问题 

这个坑爹的问题,在我拿到公司刚配的DELL OptiPlex 790型号的电脑的当天就发现了~当我兴冲冲的安装好最新的Ubuntu 11.04 Natty,打好最新的内核补丁,我发现重启后,机器没反应了。只能强制关机了~

我发现这可能是一个bug,我先是在Ubuntu的邮件列表里面提出了问题,果然很多人有这个问题,不仅仅是DELL OptiPlex 790的问题,还有DELL OptiPlex 的其他64位机型.

之后,我便向ubuntu 提交了这个bug,见:https://bugs.launchpad.net/ubuntu/+source/linux/+bug/819260

等啊等,这个bug一直没有得到修复。直到几天前,一个patch 解决了这个问题。现在只需要下载最新的linux kernel 源码,打入这个patch.编译并安装使用上该内核。重启就不会再假死拉~

下载该patch(感谢Leann Ogasawara),地址:http://ftp.xiazhengxin.name/xzx/patch/0004-UBUNTU-SAUCE-x86-reboot-Make-Dell-Optiplex-790-use-r.patch

下载最新的Linux kernel (3.0.4),地址:http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.0.4.tar.bz2

解压内核,进入目录:
1.打入重启补丁:
patch arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c /path/to/0004-UBUNTU-SAUCE-x86-reboot-Make-Dell-Optiplex-790-use-r.patch

2.编译内核:
make allyesconfig
生成临时.config 文件。


使用Ubuntu 的.config 文件编译,一般位于/boot/下,如下:
sharl@sharl-laptop:~$ ls /boot/config* -lh
-rw-r--r-- 1 root root 135K 2011-08-30 05:58 /boot/config-2.6.38-11-generic
-rw-r--r-- 1 root root 135K 2011-04-29 05:13 /boot/config-2.6.38-9-generic

复制过来,覆盖
cp /boot/config-X.X.XX-XX-generic ./.config

接来来,开始编译(时间很长~)
make

3.编译完成后,打成debian 包.
首先安装工具包:
sudo apt-get install kernel-package

之后,打包(时间也很长):
fakeroot make-kpkg --initrd --append-to-version=-by-sharl kernel-image kernel-headers

完成之后。就会在源码目录的上层目录里面发现,生成的deb包.
4.安装内核.
依次安装 linux-image、linux-headers包.
dpkg -i linux-image*
dpkg -i linux-headers*

5.关机.(现在重启还没好~)
6.再开机即可。

至此,我的DELL OptiPlex 790 就可以正常的重启拉~

注:
1.如果你不想自己重新编译内核,这里有我编译好的.可供下载.
http://ftp.xiazhengxin.name/xzx/linux-kernel/

2.DELL 其他机型重启内核补丁下载,见:
http://people.canonical.com/~ogasawara/ ... ot-quirks/

3.编译内核时,参考了Ubuntu官方文档,地址:
https://help.ubuntu.com/community/Kernel/Compile
[ ] ( 1900 次浏览 ) 永久链接 ( 3 / 2582 )
在Ubuntu 下导入CyanogenMod 的模块项目到Eclipse 

其实,这篇文章着实不应该发布在我的GNU/Linux学习站,因为这和GNU/Linux应该没有半毛钱关系~不过又实在没地方可放,所以只能发表于此了~(如果非要和GNU/Linux车上点关系,那就是是在Ubuntu下操作的 囧rz)

好了,言归正传。很多Android开发者都会或多或少的在现有项目的基础上进行二次开发,而我的工作则是基于著名的第三方Android ROM - CyanogenMod 进行的。

比如,改进下短信模块(MMS),改善下拨号界面(Contacts)等等,这个时候我就需要导入CM的单个模块到我的IDE(即Eclipse Platform)中。

一般的做法是,在Eclipse 中新建一个Android 项目,然后勾选掉“使用默认路径”,选中“使用已存在的路径”,再定位到指定模块的目录(如src/packages/apps/Mms),就可以导入了。

不过,这样的做法会有一个问题,那就是Eclipse的Egit不会认出该模块项目下的.git,也就是说我不能在导入的这个项目上使用版本控制。这的确很坑爹~

但是,这个方法也是
CM的官方WIKI(http://wiki.cyanogenmod.com/wiki/Loading_source_in_eclipse)

Android 官方的文档(http://source.android.com/source/using-eclipse.html)
里面建议的做法。

不过我本人极力的不推荐那样做,特别是前者,除了上面说到的没有GIT之外,它的.classpath 文件还会在你的项目下新增一堆用不到的文件夹。

好在,现在我找到了一个更好的办法~那就是:

1.打开Eclipse SDK.
2.选择菜单 "File"->"Import From".
3.选择GIT项下的 "From existed GIT Project".
4.点击 "Add",浏览到要导入模块的目录,如Mms.
5.点击 "Refresh",这时候会显示出 Mms.git,确定即可。
6.选择 "Import as General Project",下一步即可(要确保项目根目录下没有.project文件).
7.点击 "Finish".这个时候项目已经被导入进Eclipse了。不过还没完。
8.下载我事先准备好的模板(http://ftp.xiazhengxin.name/xzx/etc/pre-standard-template-for-android-project.7z),解压,覆盖至项目根目录下。
9.先 “Close Project”,再 "Open Project"下,最好在 "Refresh" 下。
10.右击项目,选择右键菜单 "Android Tools" -> "Fix Project Property".
11.你会发现,一个带有GIT的、可编译的CM模块项目回来了~

注:打开我提供的预模板,其实里面一共就三个文件: .project、.classpath、default.properties。
其实这些文件都是我之前以"Android Project"方式导入模块项目时,自动生成的。只不过为了以"GIT Project" 方式导入,预先删除了。待导入之后,又放进来了。

原理就是这样。
[ ] ( 2023 次浏览 ) 永久链接 ( 2.9 / 2588 )
升级安装 Hiawatha 7.6、nginx 1.1.1 和 Varnish Cache 3.0.1 RC1 

本周我所使用的web server —— Hiawatha 发布了7.6的版本,重写了关于防止SQL注入方面的模块,官方推荐升级标记为低。考虑到稳定性,我决定还是跟进,因为hiawatha 并不常更新。

还有就是我所使用的缓存服务器varnish 也放出了3.0.1的测试版 RC1,考虑到前一版本的varnishadm 有点问题,我也打算更新到该版本。

最后就是nginx 发布了1.1.1的光棍版,本来我用1.0.4版用的好好的,唯一不爽的就是时区总是不对。我怀疑是在编译安装时被定义死了,所以我便打算重新编译一个版本,看看能不能修复这个问题。

首先,停掉相关所有服务。
killall hiawatha
killall nginx
killall varnishd

删除所有旧程序,备份配置文件。

现在,开始安装新版本。首先是hiawatha.
下载源码包(http://www.hiawatha-webserver.org/files/hiawatha-7.6.tar.gz),解压,进入目录:

我的configure:
[root@PowerPC hiawatha-7.6]# ./configure \
> --prefix=/usr/local/hiawatha \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig \
> --localstatedir=/var \
> --disable-largefile \
> --enable-chroot \
> --enable-command \
> --disable-ipv6 \
> --disable-monitor \
> --disable-ssl

检查依赖,没有问题,接下来make && make install安装.一切顺利。之后,覆盖掉新生成的配置文件即可。

便可以启动hiawatha服务器了。

接来下是nginx,下载源码包(http://nginx.org/download/nginx-1.1.1.tar.gz),解压,进入目录:

我的configure:
[root@PowerPC nginx-1.1.1]# ./configure \
> --prefix=/usr/local/nginx \
> --sbin-path=/usr/local/sbin/nginx \
> --conf-path=/etc/sysconfig/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --pid-path=/var/run/nginx.pid \
> --lock-path=/tmp/nginx.lock \
> --user=http \
> --group=web \
> --with-select_module \
> --with-poll_module \
> --with-http_image_filter_module \
> --with-http_dav_module \
> --with-http_flv_module \
> --with-http_gzip_static_module \
> --without-http_ssi_module \
> --without-http_auth_basic_module \
> --without-http_geo_module \
> --without-http_rewrite_module \
> --without-http_proxy_module \
> --without-http_fastcgi_module \
> --without-http_uwsgi_module \
> --without-http_scgi_module \
> --http-log-path=/var/log/nginx/access.log \
> --http-client-body-temp-path=/tmp/nginx/request \
> --without-mail_pop3_module \
> --without-mail_imap_module \
> --without-mail_smtp_module \
> --without-pcre

检查依赖,没有任何问题。之后configure给出了编译概况,见下:

Configuration summary
+ PCRE library is disabled
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1 library is not used
+ using system zlib library

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/sbin/nginx"
nginx configuration prefix: "/etc/sysconfig/nginx"
nginx configuration file: "/etc/sysconfig/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/tmp/nginx/request"


确认一下,没有任何问题,make && make install 编译安装至指定目录。然后在恢复下配置文件,即 nginx.conf 文件。便可以启动nginx 服务器了~

最后就是varnish cache 了,下载源码包(http://repo.varnish-cache.org/source/varnish-3.0.1-rc1.tar.gz),解压,进入目录:

我的configure:
[root@PowerPC varnish-3.0.1-rc1]# ./configure \
> --prefix=/usr/local/varnish \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig \
> --localstatedir=/var \
> --disable-largefile

检查依赖,没有问题,之后便编译安装 make && make install.完了之后就是恢复下之前备份的配置文件,即 default.vcl 文件.

一切OK后。便可以启动varnish 服务器了。

试了一下,所有网站访问正常。唯一的问题……就是nginx,肿么时区还是UTC?为神马??晕了~
[ ] ( 1903 次浏览 ) 永久链接 ( 3 / 2407 )
CentOS下改变系统和nginx的时区 

我的VPS是在美国的,所以默认时区当然不可能是中国标准时间(CST),我也一直没改。不过这几天,我发现了问题,就是我的nginx是使用的我系统的默认时区(UTC),而我是使用nginx做我的ftp用户目录文件的展示的,也就是说,我上传文件的时间和用户在nginx上看到的时间是不吻合的,之间相差了8个小时~

这的确很坑爹~我决定把时区改回来。在CentOS下,有tzselect命令可以改。直接运行即可:
[root@PowerPC ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
##选择所在洲
#? 5
Please select a country.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) Macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
##选择所在国家
#? 9
Please select one of the following time zone regions.
1) east China - Beijing, Guangdong, Shanghai, etc.
2) Heilongjiang (except Mohe), Jilin
3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
4) most of Tibet & Xinjiang
5) west Tibet & Xinjiang
##选择所在城市区域
#? 1

The following information has been given:

China
east China - Beijing, Guangdong, Shanghai, etc.

Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Sat Aug 13 19:32:00 CST 2011.
Universal Time is now: Sat Aug 13 11:32:00 UTC 2011.
Is the above information OK?
1) Yes
2) No
##确认修改
#? 1

You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

至此,时区修改完成。

不过我打印了下"date"好像还是没有即时生效?!
又查了下,看来只好手动改了~

首先,删除位于/etc 下的localtime 文件。
rm -rf /etc/localtime

之后,创建一个同名的软连接到/usr/share/zoneinfo/Asia 下的Shanghai文件。
ls -s /etc/localtime /usr/share/zoneinfo/Asia/Shanghai

即可。

查看效果:
[root@PowerPC ~]# ls /etc/local* -lh
lrwxrwxrwx 1 root root 33 Aug 13 19:41 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
[root@PowerPC ~]# date
Sun Aug 21 17:14:19 CST 2011
[root@PowerPC ~]# date -u
Sun Aug 21 09:14:21 UTC 2011
[root@PowerPC ~]#

看,这样一来,时区立马生效了~

不过,系统的时区是改过来了,nginx的时区好像还是UTC.这是肿么回事?

难道要重启生效? killall nginx 杀死nginx进程
再启动,问题依旧。

难道要在配置文件指定? 根据nginx官方wiki(地址:http://wiki.nginx.org/CoreModule#env)的说明,在nginx.conf 里加上一句:

# set timezone
env TZ=CST;

重启,还是不行。

在系统变量里添加$TZ为CST,
export TZ="CST"

重启,依旧不行~

杯具~

在以“nginx change timezone”为关键词搜索的时候,看到了nginx 更新日志里面有这么一行:

*) Feature: now nginx takes into account a time zone change while
reconfiguration on FreeBSD and Linux.


难不成nginx只会在编译时候才会读取系统时区?以后要改变时区只能重新编译???!!

至于你们信不信,反正我是不信~囧rz

针对这个问题,我已经在nginx的官方邮件列表提问了(地址见:http://mailman.nginx.org/pipermail/nginx/2011-August/028562.html),现在只有等官方的回答了~
[ ] ( 3951 次浏览 ) 永久链接 ( 3 / 2473 )

<< <上一页 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 下一页> >>