yum2014 发表于 2013-04-16 18:34

如何对根目录设置重写而子目录设置不使用url重写

本帖最后由 yum2014 于 2013-04-16 18:44 编辑

主站是dokuwiki程序跑起来的wiki站点。
nginx的配置文件是server {
    listen   80; ## listen for ipv4; this line is default and implied

    root /home/data/wiki.domain.com;
    index doku.php index.php index.html index.htm;

    server_name wiki.domain.com;

    location / {
      index doku.php;
      #try_files $uri $uri/;
      try_files $uri $uri/ @dokuwiki;
    }
    location @dokuwiki {
      rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
      rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
      rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
      rewrite ^/(.*) /doku.php?id=$1 last;
    }

    location /doc {
      root /usr/share;
      autoindex on;
      allow 127.0.0.1;
      deny all;
    }
    location /images {
      root /usr/share;
      autoindex off;
    }

    location ~ \.php$ {
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
}配合dokuwiki管理后台内部的
Advanced Settings部分的userewrite===>Use nice URLs项目设置为.htacess。则可以使用

但是我希望在这个网站内再建立一个子目录。
比如在
domain.com/learnphp/下面建立一些自习php的程序。

于是修改domain.com.conf。
在location /images段落上面建立一个
    location /learnphp {
      root /opt/;
    }
而后重启nginx       
但是访问
http://wiki.domain.com/learnphp/2.php报告file not found!

错误日志显示
2013/04/16 17:49:19 7242#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.0.139, server: wiki.domain.com, request: "GET /learnphp/2.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "wiki.domain.com"

注意:在/opt/learnphp/目录下,建立一个1.htm文件。通过 http://wiki.domain.com/learnphp/1.htm 是可以访问到的!!


求问。如何对子目录设置不重写?

ps:仅仅搜到了。如何在子目录中使用另外的rewrite规则的例子------http://ilost.info/176
页: [1]
查看完整版本: 如何对根目录设置重写而子目录设置不使用url重写