一些有用apache重写规则

# 将domain.com/xxx转向www.domain.com/xxxRewriteCond %{HTTP_HOST} ^domain.com [NC]RewriteRule ^(.*)$  http://www.domain.com$1 [R=301,NC]# 将xxx.domain.com/yyy...重定向到www.domain.com/xxx/yyy..., xxx 5-20位, 字母开头只含字母, 数字以及"-"和"_"RewriteCond %{SERVER_NAME} ^([a-z][a-z0-9\-\_]{4,19})\.domain\.com [NC]RewriteRule ^(.+)$ %{SERVER_NAME}$1 [C]RewriteRule ^([a-z][a-z0-9\-\_]{4,19})\.domain\.com(.*)$ http://www.domain.com/$1$2 [R=301,NC]# 将首页www.domain.com转向www.domain.com/html/index.htmlRewriteCond %{HTTP_HOST} www\.domain\.comRewriteRule ^/$  http://www.domain.com/html/index.html [R=301,L]

Tags: apache, url_rewrite


lamp 相关配置 [Debian]

编译环境
Debian (Ubuntu)
apt-get install build-essential
apt-get install libncurses5-dev
sudo apt-get install libxml2-dev libcurl3-dev libpng-dev libmhash-dev libmcrypt-dev libxslt-dev libpspell-dev
Mysql编译安装参数
CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-Community-Server --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-ndb-debug --without-isam --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
配置成功会提示:
MySQL has a Web [...]


apache下htaccess的Invalid command 'AuthUserFile'错误

使用了apache的 .htaccess做身份认证后, 无法访问
查看日志报错如下:
"Invalid command 'AuthUserFile', perhaps misspelled or defined by a module not included in the server configuration"
google 一下, 在apache配置文件里加入如下配置
LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.soLoadModule authz_owner_module /usr/lib/apache2/modules/mod_authz_owner.soLoadModule authn_file_module  /usr/lib/apache2/modules/mod_authn_file.so
ok,问题解决

Tags: apache, htaccess, 身份验证


如何关闭time_wait连接

结合netstat和awk命令来统计网络连接数
From: http://hi.baidu.com/thinkinginlamp/blog/item/afbcab64b1ad81f3f6365453.html
netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"\t",state[key]}'
会得到类似下面的结果,具体数字会有所不同:
LAST_ACK 1
SYN_RECV 14
ESTABLISHED 79
FIN_WAIT1 28
FIN_WAIT2 3
CLOSING [...]


Apache 2.x 基于主机名的虚拟主机

NameVirtualHost *:80<VirtualHost *:80>ServerName a.lostk.comDocumentRoot e:/webserver/htdocs/aErrorLog e:/webserver/apache/logs/a.lost-error.logCustomLog e:/webserver/apache/logs/a.lost-access.log common    <Directory "e:/webserver/htdocs/a">        Options Indexes FollowSymLinks        AllowOverride None        Order allow,deny        Allow from all    </Directory></VirtualHost><VirtualHost *:80>ServerName b.lostk.comDocumentRoot e:/webserver/htdocs/bErrorLog e:/webserver/apache/logs/b.lost-error.logCustomLog e:/webserver/apache/logs/b.lost-access.log common    <Directory "e:/webserver/htdocs/b">        Options Indexes FollowSymLinks        AllowOverride None        Order allow,deny        Allow from all   [...]


QQ居然占用443端口

早上突然发现本机测试的 apache 突然无法启动了,首先想到的是配置错误,可是一直也没有动过配置文件,后来就发现443端口被qq占用了。
netstat -ano
说明
a:显示所有连接和监听的端口
n:用ip地址的形式显示地址和端口
o:显示和连接想关的进程id。
用这个方法查出占用端口的进程id
linux系统中,使用
netstat -anp
不过不知道为什么qq会占用443端口,后来qq关了再开再也没出现端口占用情况,google 了一下发现原来也有人出现这种情况:这里还有这里。有知道的能否告知一下。

Tags: 443, apache, QQ, 端口