Zend Framework 2在Nginx服务器下无法路径重写的解决办法

Here is a very simple Nginx configuration which I use:

server {
listen *:80;
server_name DOMAIN;

# Character Set
charset utf-8;

# Logs
access_log /vhosts/DOMAIN/logs/access_log main;
error_log /vhosts/DOMAIN/logs/error_log;

# Directory Indexes
index index.php;

# Document Root
root /vhosts/DOMAIN/public;

# Location
location / {
  try_files $uri $uri/ /index.php;
}

# Error Pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

# PHP-FPM Support
location ~ \.php$ {
fastcgi_pass unix:/usr/local/etc/php-fpm/DOMAIN.sock;
include fastcgi.conf;
}

# Block access to .htaccess
location ~ \.htaccess {
deny all;
}
}

最重要的是配置Location的:

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

和阻止.htaccess的:

location ~ \.htaccess {
    deny all;
}
声明:本文采用 BY-NC-SA 协议进行授权,本文链接:Zend Framework 2在Nginx服务器下无法路径重写的解决办法

发表评论