【发布时间】:2017-01-20 01:42:43
【问题描述】:
我一直在尝试使用phpbrew 升级到 php 7.1,并选择使用 nginx 安装它,因为我到处都读到它比 Apache 更简单(以我的拙见,没那么简单)。
当我尝试使用 nginx 运行 Symfony2 时,我遇到了this doc page,它提供了 nginx 上 Sf2 的基本配置。
我设法将 php-fpm 配置为服务app_dev.php,并且每个以.php 结尾的文件都正确。但是,一旦我转到不同的 URL(例如/home),nginx 配置就会中断,并且在php-fpm 中出现File not found 错误。
如何配置 nginx 虚拟主机以允许重写 app_dev.php 或 app.php 之后的所有内容(就像在 apache2 上使用 modrewrite 一样)?
我的nginx文件供参考:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location /my-app {
index web/app_dev.php;
try_files $uri /web/app.php$is_args$args;
}
location /dist {
root /usr/share/nginx/html;
index depp/index.php;
try_files $uri /depp/index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass unix:/home/gabriel/.phpbrew/php/php-7.1.0/var/run/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param REQUEST_URI $uri?$args;
}
}
【问题讨论】: