Zend Framework on nginx

2019-03-08 01:19发布

The Zend Framework based site I have been working on is now being migrated to its production server. This server turns out to be nginx (surprise!). Naturally the site does not work correctly as it was developed on Apache and relies on an htaccess file.

My question is... anyone have any experience with this? Any ideas on how to translate what the htaccess file does to an nginx.conf file? I'm researching this but am hoping someone already has experience with this. Thanks!

EDIT: This is the current 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]

8条回答
不美不萌又怎样
2楼-- · 2019-03-08 01:25

This is "official", simple and works nice:

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

查看更多
爷、活的狠高调
3楼-- · 2019-03-08 01:29

If it were at all possible, I would recommend that they setup Apache on a nonstandard port accessible only from the Nginx box, and have Nginx proxy to Apache.

Nginx Proxy documentation

查看更多
叛逆
4楼-- · 2019-03-08 01:31

If you use a subdirectory for your project like http://some.url/myproject/controller/, then you also need to add setBaseUrl to your bootstrap file.

<?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!
    }
}

The nginx rewrite would look like this:

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

PS The question mark is not typo!

查看更多
Lonely孤独者°
5楼-- · 2019-03-08 01:32

Actually i run a nginx with a drupal site that work like zend framework: one index.php as bootstrap

this is the rule (not tested on zend framework, just on drupal, but should be similar)

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

error_page  404              /index.php;
查看更多
smile是对你的礼貌
6楼-- · 2019-03-08 01:34
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;
 }
}

It's recommended to use try_files when ever possible.

查看更多
一纸荒年 Trace。
7楼-- · 2019-03-08 01:41

For staging server that could help ;)

            fastcgi_param APPLICATION_ENV staging;
查看更多
登录 后发表回答