显示标签为“webmaster”的博文。显示所有博文
显示标签为“webmaster”的博文。显示所有博文

星期一, 十一月 19, 2007

symlink for Apache DocumentRoot/Directory

/home/httpd 是 /data/httpd 的符号链接。在 httpd.conf 中,一开始使用的都是 DocumentRoot /home/httpd/$site 这样的形式,这次配置一个简单的认证,采用如下方法:
Directory "/data/httpd/$site"
AuthUserFile /usr/local/apache2/conf/.htpasswd
AuthName "SimpleAuth"
AuthType Basic
require valid-user
Options None
AllowOverride None
Order Deny,Allow
Deny from all
Allow from $ipaddr
结果无法通过验证。

把 Directory "/data/httpd/$site" 改为 Directory "/home/httpd/$site" 就可以了。

如果 /data/httpd/$site/ 下的一个页面通过 url 连接到 http://$site/ 下的某个其他页面则仍会有问题,因为显然不能自动提交认证信息。

星期三, 十一月 07, 2007

sourceforge vhost

绑定 VirtualHost。在 Project -> Admin -> Shell/DB/Web -> "Manage VHOSTs" 下,添加一个 vhost(Add New Virtual Host -> New Virtual Host),例如我原来的项目站点为 crablfs.sourceforge.net,这时增加一个 www.yourlfs.net。

然后设置 DNS。注册一个域名 yourlfs.net(¥50/年),并进行如下设置:
yourlfs.net      IN    A        66.35.250.210
www.yourlfs.net IN CNAME vhost.sourceforge.net.
svn.yourlfs.net IN CNAME crablfs.svn.sourceforge.net.

星期二, 十月 16, 2007

google sitemap

今天花了点时间了解了一下 google sitemap_gen,并在项目的文档站点上部署了一下,主要是为了使其更利于搜索以促进项目的推广。

首先从 sourceforge 上下载 sitemap_gen,解开后,拷贝 example_config.xml 为 config.xml,拷贝 example_urllist.txt 为 ulfs_urllist.txt,编辑这两个文件。config.xml 文件我只保留了 URL 和 URLLIST 两种方法,指定 base_url 和 store_into 到站点根目录下的 sitemap.xml.gz 文件,这样 google 可以通过 web 访问到这个 sitemap 文件,urllist 指向到 ulfs_urllist.txt:
http://crablfs.sourceforge.net
http://crablfs.sourceforge.net/index.html lastmod=2007-10-14T22:48:00+01:00 changefreq=monthly priority=1.0
http://crablfs.sourceforge.net/sysadm_zh_CN.html lastmod=2007-09-25T22:17+01:00 changefreq=monthly priority=0.3
http://crablfs.sourceforge.net/tree.html lastmod=2007-07-05T03:32:00+01:00 changefreq=monthly priority=0.5
http://crablfs.sourceforge.net/ru_data_man_zh_CN.html lastmod=2007-10-15T01:14:00+01:00 changefreq=weekly priority=0.6
然后上传 3 个文件:config.xml, ulfs_urllist.txt 和 sitemap_gen.py 到站点根目录下。

接着使用 ssh 登录到站点,运行 sitemap_gen.py 命令:
[chowroc@pr-shellC htdocs]$ python sitemap_gen.py --config=config.xml
Reading configuration file: config.xml
Opened URLLIST file: ulfs_urllist.txt
[WARNING] Discarded URL for not starting with the base_url: http://crablfs.sourceforge.net
Sorting and normalizing collected URLs.
Writing Sitemap file "/home/groups/c/cr/crablfs/htdocs/sitemap.xml.gz" with 4 URLs
Notifying search engines.
Notifying: www.google.com
[WARNING] Cannot contact: www.google.com
Count of file extensions on URLs:
4 .html
Number of errors: 0
Number of warnings: 2
去掉 ulfs_urllist.txt 中的第一行,在运行:
[chowroc@pr-shellC htdocs]$ python sitemap_gen.py --config=config.xml
Reading configuration file: config.xml
Opened URLLIST file: ulfs_urllist.txt
Sorting and normalizing collected URLs.
Writing Sitemap file "/home/groups/c/cr/crablfs/htdocs/sitemap.xml.gz" with 4 URLs
Notifying search engines.
Notifying: www.google.com
[WARNING] Cannot contact: www.google.com
Count of file extensions on URLs:
4 .html
Number of errors: 0
Number of warnings: 1
仍然报告无法 contact www.google.com,那么可以登录到 google 的 Webmaster tools,手工添加 sitemap,在 "Sitemaps" 中提交:
http://crablfs.sourceforge.net/sitemap.xml.gz
等待一段时间之后,可以看到已经正确提交的显示。

关于 google sitemap_gen 的使用文档在:
https://www.google.com/webmasters/tools/docs/en/sitemap-generator.html

星期五, 五月 18, 2007

apache logrotate

必须设置 Apache 的日志自动轮转,否则其日志增长可能会很快,最终撑爆硬盘。在 /etc/logroate.conf 或 /etc/logrotate.d/httpd 中加入:
/usr/local/apache2/logs/*log {
monthly
rotate 3
}
但这样还不够,因为日志轮转后,如果不重启 httpd 进程,那么日志就会写到 access_log.1 中。可以在 logroate 配置中通过如下方法来指定重启:
    postrotate
/bin/kill -HUP `cat /usr/local/apache2/logs/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}

星期一, 二月 26, 2007

apache compile so

要将模块编译成 so 共享模块,应该使用如下参数:
--enable-so --enable-foo=shared
例如:
--enable-so --enable-dav=shared --enable-dav-fs=shared --enable-dav-lock=shared

如果仅仅使用 --enable-so --enable-foo,那么 foo 这个模块就将静态连接到 httpd 中,使用 httpd -l 可以看到这个模块。

星期三, 一月 31, 2007

Apache 1.3 to 2.0 VirtualHost

原来的 Apache 1.3,其虚拟主机的设定如下:
NameVirtualHost *:80
"<"VirtualHost *">"
...
但把虚拟主机的那些配置拷贝到 Apache 2.0 中的配置文件之后,启动 Apache 得到报错"No VirtualHost found for NameVirtualHost *:80"。

排错,将所有的 VirtualHost * 替换为 VirtualHost *:80 即可。

星期三, 一月 24, 2007

Apache mod_rewrite & .htaccess for mass VirtualHost

我遇到这样的应用,在 httpd.conf 中 Include virtual.conf,而在 virtual.conf 中全部都是以 "<"VirtualHost">" 方式建立的虚拟主机,每一个虚拟主机的配置大体上一致,是由程序根据注册的情况自动添加的。

现在的要求是,针对每一个站点,可能需要定义一些 Rewrite 规则。因为 "<"VirtualHost">" 是由程序自动生成的,所以不可能在每一个 VirtualHost 中手工更改,而这又是一个商业软件,更改代码也不是那么方便。一种安全一点的考虑是在全局来实现,即编写一个全局的 Rewrite 规则,在所有的虚拟主机中都可以使用。

但这种方法实际上是行不通的。回忆一下 VirtualHost 的基础知识,如果定义了一个 VirtualHost,那么定义的很多全局变量都将失效的,而且原来的主机也需要定义成 VirtualHost 才能继续使用。对 Rewrite 也是如此。实验如下:
httpd.conf
NameVirtualHost 192.168.0.98:80
"<"VirtualHost 192.168.0.98:80">"
ServerName www1.test.com
DocumentRoot /var/www/html/dir
RewriteEngine on (1)
RewriteRule "^/index\.html" "/test.html" (2)
"<"/VirtualHost">"

"<"VirtualHost 192.168.0.98:80">"
ServerName www2.test.com
DocumentRoot /var/www/html/dir2
# RewriteEngine on
# RewriteRule "^/index.html" "/test.html"
"<"/VirtualHost">"

"<"VirtualHost 192.168.0.98:80">"
ServerName www.test.com
DocumentRoot /var/www/html/test
"<"/VirtualHost">"

$ cat /var/www/html/dir/index.html
Index of TEST 1
$ cat /var/www/html/dir/test.html
TEST 1
$ cat /var/www/html/dir2/test2.html
TEST 2
$ cat /var/www/html/test/index.html
INDEX at TEST
$ cat /var/www/html/test/test.html

$ cat /etc/hosts
...
192.168.0.98 www1.test.com
192.168.0.98 www2.test.com
192.168.0.98 www.test.com
192.168.0.98 www.example.com
将(1),(2)分别放置于全局和 VirtualHost 内,就可以看到差异。即使在 VirtualHost 之前增加如下的规则也无效:
RewriteEngine on
RewriteCond %{HTTP_HOST} "!^www.test.com$" [NC,OR]
RewriteCond %{SERVER_NAME} "!^www.test.com$" [NC]
RewriteRule "(.*)" "http://www.test.com$1
这是希望把所有不是到 www.test.com 的请求重定向到 www.test.com(记得修改 /etc/hosts 文件如上),则理论上到 www.example.com 的请求应该会转向 www.test.com,如果这样可以做到,那么我只需要增加一个虚拟主机,然后在这里定义所有的 RewriteRule,再 Rewrite 回去也许是可以的。

但实际上这样也仍然是无效的,最后连接到的仍然是和默认的一样:www1.test.com──这是符合 VirtualHost 的基本原理的。所以 VirtualHost “优先级”更高,会覆盖掉全局的 Rewrite 设置。

那么另一个解决办法就是利用 .htaccess 来实现了。所有虚拟主机的 DocumentRoot 均是 /www/users/$virtualhostname,则方法是:
$ cat httpd.conf
"<"Directory "/www/users"">"
AllowOverride FileInfo
Order Allow, Deny
Allow From All
"<"/Directory">"

$ cat /www/users/www.test04.com/.htaccess
RewriteEngine on
RewriteRule "^index\.html" "/index.php"
注意这里的正则表达式是"^index\.html"而不是象全局和 VirtualHost 段中使用的 "^/index\.html",这是因为 .htaccess 是在指定的 Directory 中,所以其使用的是一个类似于相对路径的概念,当然这里是 URL 的一个相对路径。所以"^/index\.html"将得不到任何匹配。而 RewriteRule 部分的正则匹配串则是 URL 部分去除主机名后的那部分路径,并一定以"/"开头──也就是 DocumentRoot

这样就基本上可以实现了,但开放 .htaccess 以后可能会有负载问题,目前来看,可以考虑使用 PAM 来实现对于资源的控制看是否可行?

星期日, 一月 14, 2007

Apache MPM prefork vs. work

MPM: Multi-Processing Module。

主要的区别是是否使用线程。prefork 使用线程而 work 模式不使用。

星期五, 一月 05, 2007

SSL 及电子商务在线支付

Apache basic configuration for PHP

# Apache Configuration for PHP
LoadModule php4_module modules/libphp4.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php
"<"Files *.php">"
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 9524288
"<"/Files">"

星期一, 十二月 25, 2006

reserve proxy

主要考察方面:
1. 缓存基本原理

2. 哪些内容被缓存:image, html & text, dynamic scripts 执行结果
哪些内容应该被缓存?

问题:为什么静态内容(image & text)缓存可以提高性能?
(1) 变磁盘的文件操作为内存操作
tmpfs -> /dev/shm 的使用
squid:
cache_dir ufs /dev/shm/tmp 1024 16 256
这里使用 /dev/shm/tmp 与使用普通目录的具体区别是什么?能提高性能吗?为什么?

(2) cache 服务器分担 web 服务器的部分负载

3. 缓存服务器与 web 服务器之间的负载平衡
资源分配和预留?PAM_limits?

4. 引申问题:性能监控和测试方案

5. 可缓存性:
那些数据不会被缓存:
SSL, Cookies, POST 请求, authenticateion(应该是指 Apache 的 auth 设定), user-specific information in URL, 每次都会计算出不同结果的动态页面。

是不缓存还是缓存不友好?

6. 其他问题:
(1) 手工强制刷新

(2) 统计问题

星期三, 十月 04, 2006

在 blogger 中张贴代码并保持缩进(相当于 verbatim)

google blogger 的编辑器中没有提供诸如 [CODE] 这样的环境,张贴的 python 等代码都没有缩进效果了。

解决办法是使用 "Edit Html",在代码前后增加"<"pre">""<"/pre">"。

http://blog.oasisfeng.com/2006/09/20/avoid-char-conversion-by-wordpress/