Esta é a configuração do site com base no documento oficial do Symfony2
server {
listen 80;
server_name project.local;
root /media/Storage/project/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
server {
listen 443;
server_name project.local;
root /media/Storage/project/web;
ssl on;
ssl_certificate /etc/nginx/ssl/localhost.crt;
ssl_certificate_key /etc/nginx/ssl/localhost.key;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
No começo, eu estava recebendo No input file specified.
error, no entanto li em nginx wiki que para essa configuração eu não é necessário o cgi.fix_pathinfo=0
(na verdade, eles dizem que o Symfony2 precisa que ele seja cgi.fix_pathinfo=1
).
Então eu mudei de volta para o padrão ( 1
) e agora estou recebendo File not found.
.
Eu vi outras perguntas onde eles sugerem usar location ~ \.php$ {
, no entanto, eles não foram feitos para o aplicativo Symfony2.
Gostaria de continuar com a configuração oficial do Symfony2, se possível.
Por que isso está acontecendo e qual é a solução?
EDIT 1:
Eu mudei o cgi.fix_pathinfo
de volta para 0
e mudei a configuração para isso:
server {
listen 80;
server_name project.local;
root /media/Storage/project/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ "^(.+\.php)($|/)" {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
server {
listen 443 ssl;
server_name project.local;
root /media/Storage/project/web;
ssl_certificate /etc/nginx/ssl/localhost.crt;
ssl_certificate_key /etc/nginx/ssl/localhost.key;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ "^(.+\.php)($|/)" {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
Em seguida, reiniciei o nginx e o php5-fpm, como sugerido no IRC, no entanto, obtendo o famoso erro Input file not specified
.
EDIT 2: este é o error.log
2014/06/25 22:11:45 [error] 11922#0: *3 FastCGI sent in stderr: "Unable to open primary script: /media/Storage/project/web/app_dev.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: project.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "project.local"
EDIT 3: este é o access.log
127.0.0.1 - - [25/Jun/2014:22:11:45 +0200] "GET /app_dev.php HTTP/1.1" 404 56 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/34.0.1847.116 Chrome/34.0.1847.116 Safari/537.36"
Os arquivos de log do symfony2 estão vazios. Eu não acho que o symfony tenha sido executado.
EDIT 4: Eu mudei meu confed após este SO anwser para:
server {
listen 80;
server_name project.local;
root /media/Storage/project/web;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
index app.php;
if (-f $request_filename) {
break;
}
rewrite ^(.*)$ /app.php last;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ (app|app_dev).php {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param HTTPS off;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
server {
listen 443 ssl;
server_name project.local;
root /media/Storage/project/web;
ssl_certificate /etc/nginx/ssl/localhost.crt;
ssl_certificate_key /etc/nginx/ssl/localhost.key;
error_log /var/log/nginx/ssl_error.log;
access_log /var/log/nginx/ssl_access.log;
location / {
index app.php;
if (-f $request_filename) {
break;
}
rewrite ^(.*)$ /app.php last;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ (app|app_dev).php {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
E agora estou recebendo Access denied.
error. Alguma coisa mudou :). Boo, não está funcionando ainda: (.
EDIT 5: Eu tenho chown loostro:www-data /media/Storage/project -R
e, em seguida, chmod g+s /media/Storage/project -R
, ainda recebendo Access denied
EDIT 6 : as permissões /var/run/php5-fpm.sock
são:
srw-rw---- 1 www-data www-data 0 cze 26 11:03 php5-fpm.sock
O arquivo /etc/php5/fpm/pool.d/www.conf
é o padrão (para a distribuição do Ubuntu 14.04), exceto as alterações que eu descomentei após um tutorial:
listen.owner = www-data
listen.group = www-data
listen.mode = 0660