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

我一直在尝试使用 phpbrew </ code>升级到php 7.1,并选择安装 它与nginx,因为我到处读到它比Apache简单(不是那么简单,在我的拙见)。</ p>

当我试图用nginx运行Symfony2时,我遇到了< a href =“http://symfony.com/doc/current/setup/web_server_configuration.html#nginx”rel =“nofollow noreferrer”>此文档页面,它为nginx上的Sf2提供了基本配置。< / p>

我设法配置php-fpm来提供 app_dev.php </ code>,并且每个文件都以 .php </ code>结尾。 但是,只要我转到另一个URL(例如 / home </ code>),nginx配置就会中断,我在 php-中得到 File not found </ code>错误 fpm </ code>。</ p>

如何在 app_dev.php </ code>或 app.php </ code之后配置nginx虚拟主机以允许所有内容 >要重写(与apache2上的 modrewrite </ code>一样)?</ p>

我的nginx文件供参考:</ p>

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

位置〜\ .php $ {
fastcgi_pass unix:/home/gabriel/.phpbrew/php/php-7.1.0/var/run/php-fpm.sock;
fastcgi_split_path_info ^(。+ \ .php)(/。*)$;
包括fastcgi_params ;
fastcgi_param SCRIPT_FILENAME $ realpath_root $ fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $ realpath_root;
fastcgi_param REQUEST_URI $ uri?$ args;
}
}
</ code> </ pre>
</ div>

展开原文

原文

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).

As I was trying to run Symfony2 with nginx, I came across this doc page, which gives a basic config for Sf2 on nginx.

I managed to configure php-fpm to serve app_dev.php, and every file ending in .php correctly. 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.

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)?

My nginx file for reference:

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

1个回答



您缺少重写条件来捕获所有传入的请求并将它们转发给前端控制器。</ p>
\ n

尝试类似:</ p>

 #strip app.php / prefix如果存在
则重写^ / app \ .php /?(.*)$ / 永久$ 1;

位置/我的应用{
索引app.php;
try_files $ uri @rewriteapp;
}

位置@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)(/。*)$;
包括fastcgi_params;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
}

#拒绝访问任何其他php文件
位置〜^。* \ .php(/ | $){
deny all;
}
</ code> </ pre>

您当前的配置是任何 .php </ code>脚本的更通用的配置,但Symfony2和框架一般只提供 一个全能的前端控制器。</ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐