未找到Symfony2、phpbrew、nginx、php7.1和文件
我一直在尝试使用未找到Symfony2、phpbrew、nginx、php7.1和文件,php,symfony,nginx,phpbrew,Php,Symfony,Nginx,Phpbrew,我一直在尝试使用phpbrew升级到PHP7.1,并选择使用nginx安装它,因为我到处都读到它比Apache简单(以我的拙见,没有那么简单) 当我试图用nginx运行Symfony2时,我遇到了一个问题,它提供了nginx上Sf2的基本配置 我成功地将PHPFPM配置为服务于app_dev.php,并且每个文件都以.php正确结尾。但是,只要我转到另一个URL(/home),nginx配置就会中断,我在php fpm中得到一个文件未找到错误 如何配置nginx虚拟主机以允许重写app_dev.
phpbrew
升级到PHP7.1,并选择使用nginx安装它,因为我到处都读到它比Apache简单(以我的拙见,没有那么简单)
当我试图用nginx运行Symfony2时,我遇到了一个问题,它提供了nginx上Sf2的基本配置
我成功地将PHPFPM配置为服务于app_dev.php
,并且每个文件都以.php
正确结尾。但是,只要我转到另一个URL(/home
),nginx配置就会中断,我在php fpm
中得到一个文件未找到
错误
如何配置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;
}
}
您缺少一个重写条件来捕获所有传入的请求并将它们转发给前端控制器 尝试以下方法:
# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location /my-app {
index app.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# Symfony 2 app index
location ~ ^/app\.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 $document_root$fastcgi_script_name;
}
# deny access to any other php files
location ~^.*\.php(/|$) {
deny all;
}
您当前的配置对于任何.php
脚本来说都是更通用的配置,但是Symfony2和框架通常只提供一个全面的前端控制器