【问题标题】:Can't run mod_rewrite with Phalcon application无法使用 Phalcon 应用程序运行 mod_rewrite
【发布时间】:2014-10-08 04:56:25
【问题描述】:

我使用 Ubuntu 和 nginx 1.6.2。我无法运行 Phalcon 应用程序,因为它使用 mod_rewrite 规则,但在手册中我找不到 nginx 规则,只有 Apache。这是我的配置:

server {

    listen   80;
    server_name invo;

    index index.php index.html index.htm;
    set $root_path '/home/me/invo/public';
    root $root_path;

    location / {
        try_files $uri $uri/ /index.php;

        # These rules doesn't work
        rewrite ^/$ /public/ break;
        rewrite ^(.*)$ /public/$1 break;

        if (!-e $request_filename){
                rewrite ^(.*)$ /index.php?_url=/$1 break;
        }
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}

我评论了三个对我不起作用的规则。我一直打开 http: //invo/cat/index http: //invo/something 我总是看到主页。

这是 Apache 的 Phalcon 规则:

# /invo/.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

# /invo/public/.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

【问题讨论】:

    标签: mod-rewrite nginx phalcon


    【解决方案1】:

    这是我的结果工作配置:

    server {
        listen   80;
        server_name invo;
    
        index index.php index.html index.htm;
        set $root_path '/home/me/invo/public';
        root $root_path;
    
        try_files $uri $uri/ @rewrite;
    
        location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/$1;
        }
    
        location ~ \.php {
            fastcgi_index /index.php;
    
            # The difference from Phalcon manual in this line
            fastcgi_pass unix:/var/run/php5-fpm.sock; 
            include /etc/nginx/fastcgi_params;
    
            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
    
            # Comment out this line too
            #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    
        location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
            root $root_path;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 2017-01-12
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多