【问题标题】:Migrate Kohana from Apache to NginX将 Kohana 从 Apache 迁移到 NginX
【发布时间】:2014-06-04 23:26:46
【问题描述】:

我正在将 Kohana 应用程序 3.0.4 版从 Apache 迁移到 NginX。 我在配置.htaccess 时遇到问题。在 NginX 上,只有内部 URL 才能正常工作:

 http://myurlwithoutwww.net.ds/internalpage/anotherpage

但不在首页

 http://myurlwithoutwww.net.ds/

下面:

 http://myurlwithoutwww.net.ds/index.php

有效。最后两个将简单地显示一个空白屏幕。

这是我尝试迁移的 htaccess 文件:

    AddType text/x-component .htc
#Accept-Encoding: filter,deflate
# Turn on URL rewriting
RewriteEngine On
AddDefaultCharset UTF-8 

# Installation directory
RewriteBase /

RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+).([a-z]{2,3})$       [NC]
RewriteRule ^(.*)$       http://www.%{HTTP_HOST}/$1         [L,R=301]

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

#   ExpiresActive On
#   <FilesMatch \.(bmp|png|gif|jpe?g|html?|ico|doc|swf)$>
#        ExpiresDefault "access plus 10 days"
#   </FilesMatch>

FileETag none

# Protect application and system files from being viewed
RewriteRule ^async/?(.*)?                   index.php?dispatcher=async&$1 [NC,L,QSA]
RewriteRule ^(?:_application|_modules|_system)\b index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php?kohana_uri=$0 [PT,L,QSA]
#RewriteRule .* index.php/$0 [PT]

这是我当前的 Nginx 配置:

    server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;
   include /etc/nginx/aliases.conf;
   root   /var/www/webroot/ROOT;
   index  index.php;

   location / {
   expires off;
       try_files $uri $uri/ @kohana;
   }

   # Prevent access to hidden files
   location ~ /\. {
    deny all;
   }

   location @kohana {
    rewrite ^/(.+)$ /index.php$request_uri last;
   }

   location ~* \.php {

            #location ~ /\. { deny all; access_log off; log_not_found off; }
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /var/www/webroot/ROOT/$fastcgi_script_name;
    fastcgi_param KOHANA_ENV development;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT /var/www/webroot/ROOT;
            fastcgi_index index.php;
    }

【问题讨论】:

    标签: .htaccess nginx kohana


    【解决方案1】:

    试试下面的配置,如果它有 'index_file' => FALSE,还要检查 bootstrap init。

        server {
        listen       80;
        server_name  *.domain.com;
    
        client_max_body_size 20M;
    
        access_log /home/user/public_html/site/log/access.log;
        error_log  /home/user/public_html/site/log/error.log;
    
        root       /home/user/public_html/site/public/;
        index      index.php;
    
        location / {
                    # don’t check $uri/, send to php for nice error message
                    try_files $uri /index.php?$query_string;
        }
    
        location = /index.php {
            include       fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
        }
    }
    

    【讨论】:

      【解决方案2】:

      这是一个很老的问题,但也许你会发现它很有用,就像我做的那样:

      location / {
      index  index.html index.htm index.php;
      try_files  $uri index.php;
      }
      
      location /kohana {
      
      rewrite ^(.+)$ /kohana/index.php?kohana_uri=$1 last;
      if (-f $request_filename) {
      
                          break;
                  }
                  if (!-e $request_filename) {
                          rewrite ^/kohana/(.+)$ /kohana/index.php?kohana_uri=$1 last;
                  }
      }
      

      我刚刚列出了 default.conf 的主要部分。

      【讨论】:

      • nginxif is evil 中——难道没有办法将try_filesrewrite 结合使用吗?
      猜你喜欢
      • 1970-01-01
      • 2014-05-28
      • 2016-12-26
      • 1970-01-01
      • 2019-11-07
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      相关资源
      最近更新 更多