Tagged: apache RSS

  • admin 3:17 pm on October 22, 2009 Permalink | Reply
    Tags: apache, ,   

    apache mod_negotiation与MultiViews的奥妙 

    今天遇到一个奇怪的问题,取URL请求字符串时,明明访问的是/index/welcome/,取回来的却是/welcome/。
    框架在处理这个问题时的处理流程是:

    $php_self = $_SERVER['PHP_SELF'];
    $uri = $_SERVER['REQUEST_URI'];

    if (isset($_SERVER['PATH_INFO'])) {
    $uri = $_SERVER['PATH_INFO'];
    } else {
    $uri = substr($uri, strlen(dirname($php_self)) );
    }
    $uri[0]!=’?’ || $uri = “/$uri”;
    $uri = strtok($uri, ‘?’);

    先判断PATH_INFO,然后再处理其他情况。
    但我这里直接是http://xxx.com/index/welcome/ 怎么会存在PATH_INFO变量呢?
    后来打印$_SERVER变量时发现,apache认为我访问的这个链接是/index.php/welcome/ !
    原来apache可以在访问/path/foo时,如果找不到/path/foo,就会去找/path/foo.*,并且选一个合适的返回来,为你服务。
    我这里存在着/index.php,所以访问/index/welcome/时,它就自动去找/index.php了!
    而这些功能是一个模块提供的,它的名字叫mod_negotiation。相关说明:http://httpd.apache.org/docs/2.2/content-negotiation.html
    同时,这个模块还提供了一个目录级别的控制开关,也就是

    网上有很多相关的问题,但很多回复都没有回中点子上,比如:

    http://www.phpx.com/happy/thread-125808-1-1.html

    大多人都是想到用url rewrite来实现,呵呵。

    其实,这个模块还有很多其他的强大功能,等待我们去发现,嘿嘿。

     
  • admin 11:47 am on July 24, 2009 Permalink | Reply
    Tags: apache, , rewrite   

    小心对待rewrite中邪恶的百分号(%) 

    今天遇到一个非常诡异的问题。

    我目前是采用 /key1/value1/key2/value2 方式传递参数,非常干净明了。但是今天我试图传递一个urlencode过的字符串时发现,只要URI里带有百分号%,就会导致Apache服务器400错误,警告说“错误的请求”。

    /key1/value1/key2/value_with_%_symbol    400 error

    /key1/value1/key2/value_without_symbol    200 OK

    查阅手册后,发现%是rewrite语法中的特殊字符,会认为是一个变量的开始,就像PHP中的美元符号$。

    经测试,很多知名站点也没有解决这个问题,如WP,discuz,osnews等等。

    目前找到一个解决方案,但情况有点不太一样,所以也没有测试成功。链接地址:http://stackoverflow.com/questions/734654/modrewrite-doesnt-work-for-a-url-beginning-in-percent-sign

    临时解决方案:/key1/value2/?key2=evil_value2 即换回传统的方式来解决问题。

    特留此文,以后找到方案时更新。

     
    • 小诗 11:21 am on June 25, 2010 Permalink | Reply

      这个问题可以解决了。
      在wp里的重写规则是:

      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ – [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]

      然后用php中的:$_SERVER['REQUEST_URI']获取网址斜杠后的字符串。
      如:
      xx.com/%BF%AA%D0%C4
      $_SERVER['REQUEST_URI'] 就等于 /%BF%AA%D0%C4

    • 淡淡的阳光 4:51 pm on June 26, 2010 Permalink | Reply

      你的路径写得就有问题,如果访问的文件名包含’%',那么合理的url就应该是

      /key1/value1/key2/value_with_%25_symbol
      而不是
      /key1/value1/key2/value_with_%_symbol

    • admin 1:14 pm on July 1, 2010 Permalink | Reply

      @淡淡的阳光
      对的,应该先urlencode。

  • admin 2:07 pm on June 5, 2008 Permalink | Reply
    Tags: apache,   

    suexec 

    重新编译Apache

     

    XML/HTML代码
    1. ./configure –prefix=/usr/local/httpd2 –sbindir=/usr/local/httpd2/sbin –enable-so –enable-rewrite=shared –enable-deflate –enable-nonportable-atomics –with-ssl=/usr/lib64/openssl –with-expat=builtin –enable-suexec –with-suexec-caller=www –with-suexec-userdir=public_html –with-suexec-docroot=/www/htdocs –with-suexec-uidmin=103 –with-suexec-gidmin=504  

     

    在虚拟主机:

    XML/HTML代码
    1. SuexecUserGroup seaprince vhostuser  
    2. ScriptAlias /cgi-bin/ /www/htdocs/public_users/blog.eaxi.com/public_html/cgi-bin/  
    3. <Location "/php-cgi/php">  
    4.         SetHandler fcgid-script  
    5.         Options ExecCGI  
    6.         Allow from all  
    7. </Location>  

    家目录:

     

     

    XML/HTML代码
    1. mkdir -p ~/public_html/cgi-bin  
    2. cp /usr/local/php5/bin/php-cgi ~/public_html/cgi-bin/php.cgi  
    3. chown seaprince.vhostuser -R /public_html/cgi-bin/  

    重启Apache

     

     
  • admin 7:21 pm on February 14, 2008 Permalink | Reply
    Tags: apache, ,   

    Beesn Server Package 

     
  • admin 4:38 am on August 22, 2007 Permalink | Reply
    Tags: apache   

    个性化你的Apache 

    今天晚上把Apache2.2.4编译了一遍又一遍,颇有味道。若有同好者,请看此文。

    1. apr.
    apr=Apache portable runtime, official website here: http://apr.apache.org
    View Informations:

    C++代码
    1. # path/to/httpd/bin/httpd -V  

    It will show something like this:

    C++代码
    1. Server version: Apache/2.2.4 (UNIX/EAXI.COM)  
    2. Server built:   Aug 22 2007 12:28:35  
    3. Server’s Module Magic Number: 20051115:4  
    4. Server loaded:  APR 1.2.8-dev, APR-Util 1.2.8  
    5. Compiled using: APR 1.2.8-dev, APR-Util 1.2.8  
    6. Architecture:   32-bit  
    7. Server MPM:     Prefork  
    8.   threaded:     no  
    9.     forked:     yes (variable process count)  
    10. Server compiled with….  
    11.  -D APACHE_MPM_DIR="server/mpm/prefork"  
    12.  -D APR_HAS_SENDFILE  
    13.  -D APR_HAS_MMAP  
    14.  -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)  
    15.  -D APR_USE_SYSVSEM_SERIALIZE  
    16.  -D APR_USE_PTHREAD_SERIALIZE  
    17.  -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT  
    18.  -D APR_HAS_OTHER_CHILD  
    19.  -D AP_HAVE_RELIABLE_PIPED_LOGS  
    20.  -D DYNAMIC_MODULE_LIMIT=128  
    21.  -D HTTPD_ROOT="/usr/local//httpd/"  
    22.  -D SUEXEC_BIN="/usr/local//httpd//bin/suexec"  
    23.  -D DEFAULT_PIDLOG="logs/httpd.pid"  
    24.  -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"  
    25.  -D DEFAULT_LOCKFILE="logs/accept.lock"  
    26.  -D DEFAULT_ERRORLOG="logs/error_log"  
    27.  -D AP_TYPES_CONFIG_FILE="conf/mime.types"  
    28.  -D SERVER_CONFIG_FILE="conf/httpd.conf"  

    apr version informations at: path/to/httpd-src/srclib/apr/include/apr_version.h

    2. Operating System Information
    It will be displayed at error pages, httpd -V informations list.
    os info at path/to/httpd-src/os/

    3. Apache release
    It will be displayed at error pages, httpd -V informations list.
    Apache release informations defined at path/to/httpd-src/include/ap_release.h

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel