在Zend框架基于网站,我一直在努力,现在被迁移到其生产服务器。该服务器原来是nginx的(惊喜!)。当然,因为它是在Apache开发并依赖于一个htaccess文件的网站不能正常工作。

我的问题是...任何人有这样的经验吗?如何翻译一下htaccess文件做一个nginx.conf文件的任何想法?我研究这个,但我希望有人已经有了这方面的经验。谢谢!

编辑:这是当前htaccess的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
有帮助吗?

解决方案

我知道这是一个很老的线程,但它可能会帮助一些人呢。

基本上,它重定向任何404错误的index.php,但如果该文件存在(类型文件)它将设置正确的根。

我做到了,从我的头顶。它可能无法正常工作马上,你必须把正确的路径和FastCGI配置。我也把一切回到index.php文件,它应该像与Zend_Framework

error_page  404 = /index.php;

location / {
    if (-f $request_filename) {
        root   /var/www;
    }
}

location ~ \.php$ {
        fastcgi_pass   unix:/tmp/php.sock;
        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME     /var/www/index.php;
        include /etc/nginx/fastcgi_params;
}

其他提示

server {

 listen   80; ## listen for ipv4
 listen   [::]:80 default ipv6only=on; ## listen for ipv6

 server_name  localhost;

 access_log  /var/log/nginx/localhost.access.log;
 error_log  /var/log/nginx/localhost.error.log;

 root   /var/www/localhost/public;

 try_files $uri @php_index;

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location @php_index {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_param  SCRIPT_FILENAME /var/www/localhost/index.php;
  include fastcgi_params;
 }
}

我们建议当过可以使用try_files。

我不知道到htaccess的文件转换任何自动/系统的方式,你可能不得不做手工。的 Nginx的维基是用于nginx的文档的最佳资源。

修改 我现在对Nginx的运行Zend框架我和配置是这样的:

server {
  listen 80;
  server_name servername.com;

  root /var/www/zendapp/public;

  location / {
    index index.php;
  }

  # Deny access to sensitive files.
  location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ {
    deny all;
  }
  location ~ \.htaccess {
    deny all;
  }

  # Rewrite rule adapted from zendapp/public/.htaccess
  if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
  }

  # PHP scripts will be forwarded to fastcgi processess.
  # Remember that the `fastcgi_pass` directive must specify the same
  # port on which `spawn-fcgi` runs.
  location ~ \.php$ {
    include /etc/nginx/fastcgi_params;

    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
  }

  location = /50x.html {
      root   /var/www/default;
  }
}

正如你所看到的,重写规则本身是很简单的。

这是 “官方” 的,简单而漂亮的作品:

http://wiki.nginx.org/Zend_Framework#Time_for_nginx

有关临时服务器,可以帮助;)

            fastcgi_param APPLICATION_ENV staging;

实际上我运行与该工作像Zend框架Drupal站点一个nginx的:一个的index.php作为自举

这是规则(上Zend框架没有测试,只是在drupal的,但应该是相似的)

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

error_page  404              /index.php;

如果您使用了为你的项目的子目录 HTTP://some.url/myproject/controller/ ,那么你还需要setBaseUrl添加到您的引导文件。

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initSomeFancyName()
    {
        $this->bootstrap('frontController');
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->setBaseUrl('/myproject'); // set the base url!
    }
}

nginx的重写是这样的:

location /myproject/ {
  if (!-e $request_filename) {
    rewrite ^/myproject/(.*)$ /index.php?$1? last;
  }
}

PS问号不错字!

如果它是在所有可能,我会建议他们安装的Apache只能从Nginx的对话框访问和非标准端口有Nginx的代理到Apache。

Nginx的代理文档

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top