目前我正在使用 nginx 开发 cakephp。我在运行 Nginx 和 Fact CGI 的 Centos 服务器上设置了 cakephp 环境。问题是我无法在我的虚拟主机中正确设置重写规则,以便 cake 正确渲染页面,即样式等。 我的 .conf 文件是 -
#The default server
server {
listen 80 default_server;
server_name 1 23.123.123.123;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
最佳答案
下面 Luchomolina 的回答让我朝着正确的方向开始。但是,CSS 和 JS 文件不再对非顶级 URL 起作用,例如/posts 有效,但/posts/title123 无效。
这就是最终为我工作的内容:
location / {
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/(.+)$ /index.php?url=$1 last;
break;
}
set $new_uri $uri;
}
关于cakephp - 如何在nginx中配置cakephp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14704982/