简体   繁体   English

找不到Symfony2,phpbrew,nginx,php 7.1和文件

[英]Symfony2, phpbrew, nginx, php 7.1 and File not found

I've been attempting to upgrade to php 7.1 using phpbrew , and elected to install it with nginx, as I read everywhere that it was simpler than Apache (not that simple, in my humble opinion). 我一直在尝试使用phpbrew升级到php 7.1,并选择使用nginx进行安装,因为到处都读到它比Apache更简单(以我的愚见,不是那么简单)。

As I was trying to run Symfony2 with nginx, I came across this doc page , which gives a basic config for Sf2 on nginx. 当我尝试使用nginx运行Symfony2时,遇到了该文档页面 ,该页面为nginx上的Sf2提供了基本配置。

I managed to configure php-fpm to serve app_dev.php , and every file ending in .php correctly. 我设法将php-fpm配置为提供app_dev.php ,并且每个以.php结尾的.php正确。 However, as soon as I go to a different URL ( /home for instance), the nginx config breaks and I get a File not found error in php-fpm . 但是,一旦我转到另一个URL(例如/home ),nginx配置就会中断,并且在php-fpm出现File not found错误。

How do I configure the nginx virtual host to allow for everything after app_dev.php or app.php to be rewritten (as it would with modrewrite on apache2)? 如何配置nginx虚拟主机以允许重写app_dev.phpapp.php之后的所有内容(就像在apache2上使用modrewrite )?

My nginx file for reference: 我的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;
    }
}

You are missing a rewrite condition to catch-all the incoming requests and forward them to your front controller. 您缺少重写条件来捕获所有传入请求并将它们转发到前端控制器。

Try something like: 尝试类似:

  # 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;
   }

You current configuration is a more general configuration for any .php script but Symfony2 and framework in general only provide a catch-all front-controller. 您当前的配置是任何.php脚本的更常规配置,但Symfony2和框架通常仅提供了一个万能的前端控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM