HTTP协议中的url,你知道多少呢?
今天有人问我如何来匹配锚点部分的内容,一下子把握问到了,如何来匹配锚点,如何来确定两个url是否是一致的?
只好翻阅了一下http协议的文档以及 w3c关于uri部分的说明文档。找到了定义如下:
一 关于两个url是否是一致的?
HTTP歇息中关于url的格式定义如下:
http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
可以看到port可选、query也是可选的。
如果没有给port的话,默认用的就是大家都知道的80端口,abs_path是根据你服务器配置的document root的相对路径,如果为空的话,表示对应的是根目录 ‘/’。
在http协议中规定,除了下面几点外,url的比较是大小写敏感的:
1 没有写明端口的,和默认的端口的是一样的。
2 host(主机或者域名部分)是大小写不敏感的
3 如果路径部分是空的话,等同于/
4 字符html转义前后都是一样的。如~转义为%7e或者%7E
5 这里并没有说明我常常遇到的锚节点(#test)的情况,其实在比较url时,锚节点是不参与比较的。
譬如说下面这三条url就是一样的:
http://abc.com:80/~smith/home.html
http://ABC.com/%7Esmith/home.html
http://ABC.com:/%7esmith/home.html
附英文:
If the port is empty or not given, port 80 is assumed. The semantics are that the identified resource is located at the server listening for ...
lighttpd已经安装了,接下来就简单的来优化配置一下你的lighttpd配置吧。虽然默认的已经好用了,不过针对你的站点的业务的一点优化可能会带来更好的效果。
注意:这里需要根据你自己的站点来配置!
server.event-handler = "linux-sysepoll" # Linux环境下epoll系统调用可提高吞吐量
server.max-fds = 4096 # 默认的,如果站点的小文件过多的话,这个值就不够用了,建议增大,我增进维护的一个站点,这个值是65536
server.max-connections = 4096 # 默认等于 server.max-fds,如果并发量很大,建议这里也需要增大
server.network-backend = "linux-sendfile" #作为静态文件服务器,这里直接使用sendfile的形式来发送文件,能够在网络层得到快速的处理
server.max-keep-alive-requests = 0 # 对于小文件很多的请求,这里个人建议根据页面中小元素的个数来开这个值。这样的话就不用每个小元素的请求都需要单独的建立一次连接。如果只是作为fastcgi服务器的话,个人建议这里设置为0,关闭长连接,因为这样的请求是不多的。
详细的说明如下:
1 server.network-backend
网络系统调用函数的选择,可以在更底层提高网络传输的性能。
The basic network interface for all platforms at the syscalls read() and write(). Every modern OS provides its own syscall to help network servers transfer files as fast ...
lighttpd是一个优秀的静态文件服务器。基于epoll加多线程、插件模块很多,能力超强,我的vps默认使用的就是lighttpd,性能不错。
一 为什么要使用lighttpd
apache不可以吗?
在支持纯静态的对象时,比如图片,文件等 ,
lighttpd速度更快,更理想
至于它和apache的比较,很多文档,大家可以google一下
二 从何处下载lighttpd
http://www.lighttpd.net/download/这个是它的官方站
三 如何安装
1,编译安装
./configure --prefix=/usr/local/lighttpd
make
make install
configure完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在enable的模块中一定要有“mod_rewrite”这一项,否则重新检查pcre是否安装。
2,编译后配置
cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir /etc/lighttpd
cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
如果你的Linux是RedHat/CentOS,那么:
cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd
如果你的Linux是SuSE,那么:
cp doc/rc.lighttpd /etc/init.d/lighttpd
其他Linux发行版本可以自行参考该文件内容进行修改。
然后修改/etc/init.d/lighttpd,把
LIGHTTPD_BIN=/usr/sbin/lighttpd
改为
LIGHTTPD_BIN=/usr/local/lighttpd/sbin/lighttpd
此脚本用来控制lighttpd的启动关闭和重起:
/etc/init.d/lighttpd start
/etc/init.d/lighttpd stop
/etc/init.d/lighttpd restart
四 配置
修改/etc/lighttpd/lighttpd.conf
1)server.modules
取消需要用到模块的注释,mod_rewrite,mod_access,mod_fastcgi,mod_simple_vhost,mod_cgi, mod_compress,mod_accesslog, mod_expire是一般需要用到的。
其中"mod_expire"和"mod_compress"尤其重要,一个是设置页面素材的过期时间,一个是压缩页面素材;对于加速你的站点很有用处。
2)server.document-root, server.error-log,accesslog.filename需要指定相应的目录
server.document-root = "/www/phc/html/"
mkdir /usr/local/lighttpd/logs
chmod 777 /usr/local/lighttpd/logs/
touch /usr/local/lighttpd/logs/error.log
chmod 777 /usr/local/lighttpd/logs/error.log
server.errorlog = "/usr/local/lighttpd/logs/error.log"
accesslog.filename ...