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 w
This is "official", simple and works nice:
http://wiki.nginx.org/Zend_Framework#Time_for_nginx
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.
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
For staging server that could help ;)
fastcgi_param APPLICATION_ENV staging;
I don't know of any automatic/systematic way to convert the htaccess-file, you'll probably have to do it manually. The Nginx wiki is the best resource for nginx documentation.
Edit: I'm running Zend Framework on Nginx myself now and the config looks like this:
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;
}
}
As you can see, the rewrite rule itself is very simple.
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!