[英]Symfony2, phpbrew, nginx, php 7.1 and File not found
我一直在嘗試使用phpbrew
升級到php 7.1,並選擇使用nginx進行安裝,因為到處都讀到它比Apache更簡單(以我的愚見,不是那么簡單)。
當我嘗試使用nginx運行Symfony2時,遇到了該文檔頁面 ,該頁面為nginx上的Sf2提供了基本配置。
我設法將php-fpm配置為提供app_dev.php
,並且每個以.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;
}
}
您缺少重寫條件來捕獲所有傳入請求並將它們轉發到前端控制器。
嘗試類似:
# 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和框架通常僅提供了一個萬能的前端控制器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.