Archive for the ‘web网站优化’ Category

方维整站系统伪静态实现

 方维整站系统伪静态实现
默认给的文件是.htassess
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.50
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

启用后无法访问,查看错误日志,有如下内容,

Apache错误日志
[Thu Apr 22 15:34:57 2010] [error] [client 123.122.83.2] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that Re
writeRule directive is forbidden: /var/www/website/admin.php

在apache配置文件或虚拟主机网站目录下.htaccess文件中修改或增加如下Options选项
Options +FollowSymLinks
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.50
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

说明:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
以上两条是apache的rewrite规则的条件配置,
“RewriteCond指令定义了规则生效的条件,即在一个RewriteRule指令之前可以有一个或多个RewriteCond指令。条件之后的重写规则仅在当前URI与Pattern匹配并且满足此处的条件(TestString能够与CondPattern匹配)时才会起作用。”
!-d  说明“REQUEST_FILENAME”如果不是目录,则匹配
!-f   说明”REQUEST_FILENAME“如果不是文件,则匹配
匹配成功后则rewrite到index.php

QSA说明:   Query   String   Append  
   
  This   flag   forces   the   rewriting   engine   to   append   a   query   string   part   in   the   substitution   string   to   the   existing   one   instead   of   replacing   it.   Use   this   when   you   want   to   add   more   data   to   the   query   string   via   a   rewrite   rule.

为了有利于保护安全性,IE已限制此网页运行可以访问计算机的脚本或 ActiveX 控件

 

如何消除ie上的tip:为了有利于保护安全性,IE已限制此网页运行可以访问计算机的脚本或 ActiveX 控件。

做大作业时碰到,代码中加入js后出现,以前一直不在意,但如果大作业的网页上有这个按mentor的话来说用户体验就差了。。。(虽然很怀疑那个懒用户会不会好好看)

如果你的HTML文件中有这句话

<html xmlns:v=”urn:schemas-microsoft-com:vml” xmlns:o=”urn:schemas-microsoft-com:office:office” xmlns=”http://www.w3.org/TR/REC-html40“>
那直接加入下面这句话就行了

<!– saved from url=(0022)http://www.hardwork.cn/abc/ –>
没有的话.用这两句记住要放在<head>的前面

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<!– saved from url=(0022)http://www.hardwork.cn/abc/ –>

使用telnet查看web服务器排错。

命令行下测试web网站返回代码:
telnet www.hardwork.cn 80
GET / HTTP/1.1
Host: www.hardwork.cn

解决Nginx + PHP(FastCGI)遇到的502 Bad Gateway错误

解决Nginx + PHP(FastCGI)遇到的502 Bad Gateway错误

昨日,有朋友问我,他将Web服务器换成Nginx 0.6.31  + PHP 4.4.7(FastCGI)后,有时候访问会出现“502 Bad Gateway”错误,如何解决。

  我让按照以下两个步骤去解决,最后在第2步中将FastCGI的timeout时间增加为300,问题解决:

  PS:比较羡慕迅雷的Web服务器,16G内存。


  1、查看当前的PHP FastCGI进程数是否够用:

netstat -anpo | grep “php-cgi” | wc -l

  如果实际使用的“FastCGI进程数”接近预设的“FastCGI进程数”,那么,说明“FastCGI进程数”不够用,需要增大。


  2、部分PHP程序的执行时间超过了Nginx的等待时间,可以适当增加nginx.conf配置文件中FastCGI的timeout时间,例如:

……
http
{
……
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
……
}
……

浏览器访问服务器的速度问题分析

之前看资料,有多次看到过说ie浏览器的客户端在与一个服务器之间(特指http 服务)最多建立2个TCP连接来传输http request。F5可以利用express connect通过增加域名的方式来增加连接数。
我观察过多次,访问我的网站 总能看到10个连接
TCP    192.168.0.185:3632     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3633     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3634     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3635     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3636     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3637     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3638     203.171.232.42:80      ESTABLISHED
TCP    192.168.0.185:3639     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3640     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3641     125.76.229.121:80      ESTABLISHED
TCP    192.168.0.185:3642     125.76.229.121:80      ESTABLISHED

这就让我迷惑。今天在网上一番google,终于明白了点:
原来根据RF2616的要求,客户端和同一个server之间确实只能建立不超过2个TCP(http 1.1是2个,1.0是4个连接)连接以避免拥塞
Clients that use persistent connections SHOULD limit the number of simultaneous connections that they maintain to a given server. A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy. A proxy SHOULD use up to 2*N connections to another server or proxy, where N is the number of simultaneously active users. These guidelines are intended to improve HTTP response times and avoid congestion.

但是这个不是绝对的,不同的浏览器行为可能并不一样。对于IE有这样一个注册表设置:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings

MaxConnectionsPerServer REG_DWORD (Default 2)
Sets the number of simultaneous requests to a single HTTP 1.1 Server

MaxConnectionsPer1_0Server REG_DWORD (Default 4)
Sets the number of simultaneous requests to a single HTTP 1.0 Server

这是标准的,但是我的电脑是IE7,他们的值都是10,我想在IE8应该也是这样吧
我查了微软的文档,http://support.microsoft.com/kb/183110/en-us,6.0(含)以前的版本应该都是2. 大家可以验证下。

我将限制值改为2后,再查看发现确实只能同时建立2个TCP连接了。
  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:443            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:2869           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:15000          0.0.0.0:0              LISTENING
  TCP    127.0.0.1:1045         0.0.0.0:0              LISTENING
  TCP    127.0.0.1:1100         0.0.0.0:0              LISTENING
  TCP    127.0.0.1:62514        0.0.0.0:0              LISTENING
  TCP    192.168.0.185:139      0.0.0.0:0              LISTENING
  TCP    192.168.0.185:1071     219.133.60.243:8000    CLOSE_WAIT
  TCP    192.168.0.185:2307     121.0.19.146:16000     ESTABLISHED
  TCP    192.168.0.185:3609     60.28.183.195:80       TIME_WAIT
  TCP    192.168.0.185:3615     60.28.183.195:80       TIME_WAIT
  TCP    192.168.0.185:3618     125.76.229.121:80      ESTABLISHED
  TCP    192.168.0.185:3619     125.76.229.121:80      ESTABLISHED
  TCP    192.168.0.185:3620     203.171.232.42:80      ESTABLISHED
  TCP    192.168.0.185:3621     125.46.105.130:80      ESTABLISHED
  TCP    192.168.0.185:3623     60.12.231.25:80        ESTABLISHED
  TCP    192.168.0.185:3624     60.12.231.15:80        ESTABLISHED
  TCP    192.168.0.185:3625     61.189.20.200:80       SYN_SENT
  TCP    192.168.0.185:4952     207.46.107.64:1863     ESTABLISHED
  TCP    192.168.0.185:4989     207.46.26.130:1863     ESTABLISHED
  TCP    192.168.0.185:4990     64.4.36.22:1863        ESTABLISHED
  TCP    192.168.0.185:4991     207.46.26.76:1863      ESTABLISHED
  TCP    192.168.0.185:4992     65.54.171.33:1863      ESTABLISHED
  TCP    192.168.0.185:4993     65.54.171.39:1863      ESTABLISHED
  TCP    192.168.0.185:4995     207.46.26.153:1863     ESTABLISHED
  TCP    192.168.124.1:139      0.0.0.0:0              LISTENING
  TCP    192.168.194.1:139      0.0.0.0:0              LISTENING


京ICP备07010914号