这是基于官方Symfony2文档的网站configuration
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 input file specified. 错误,但是我已经阅读了nginx wiki上的这个configuration,我不需要cgi.fix_pathinfo=0 (实际上,他们说Symfony2需要它是cgi.fix_pathinfo=1 )。
所以我已经把它改回默认( 1 ),现在我File not found. 。
我已经看到了其他问题 ,他们build议使用location ~ \.php$ { ,但是他们不是为了Symfony2应用程序。
如果可能的话,我想坚持使用Symfony2官方configuration。
为什么会发生这种情况,解决scheme是什么?
编辑1:
我已经将cgi.fix_pathinfo更改回0 ,并将configuration更改为:
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; }
然后重新启动nginx和php5-fpm,如IRC上build议的,但是,得到着名的Input file not specified错误。
编辑2:这是error.log
2014/06/25 22:11:45 [error] 11922#0:* 3在stderr中发送了FastCGI:“无法打开主脚本:/media/Storage/project/web/app_dev.php(没有这样的文件或目录) “在读取来自上游的响应头时,客户端:127.0.0.1,server:project.local,请求:”GET /app_dev.php HTTP / 1.1“,上游:”fastcgi:// unix:/ var / run / php5-fpm .sock:“,主机:”project.local“
编辑3:这是access.log
“GET /app_dev.php HTTP / 1.1”404 56“ – ”“Mozilla / 5.0(X11; Linux x86_64)AppleWebKit / 537.36(KHTML ,像壁虎)Ubuntu的铬/ 34.0.1847.116铬/ 34.0.1847.116的Safari / 537.36“
symfony2日志文件是空的。 我不认为symfony曾经被执行过。
编辑4:我已经改变了我的配合下面这个SO anserser :
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; } }
而现在我得到了Access denied. 错误。 耶,有些改变:)。 嘘,还没有工作:(。
编辑5:我已经chown loostro:www-data /media/Storage/project -R然后chmod g+s /media/Storage/project -R ,仍然Access denied
编辑6 : /var/run/php5-fpm.sock权限是:
srw-rw---- 1 www-data www-data 0 cze 26 11:03 php5-fpm.sock
/etc/php5/fpm/pool.d/www.conf文件是默认的(对于Ubuntu 14.04发行版),除了我在下面的教程中取消注释的这些更改:
listen.owner = www-data listen.group = www-data listen.mode = 0660
总结 :我的问题是错误的文件权限。 nginx的官方symfony2 configuration是可以的。 我把我的文件移动到一个NTFS存储驱动器,似乎在移动文件权限已更改。
chown loostro:www-data -R /media/Storage/project – 将所有者更改为loostro并将其组合为www-data(loostro是我开发该应用程序的用户,php5-fpm作为www-data运行) chmod 755 -R /media/Storage/project – recursion地将项目的文件权限更改为rwx(所有者)rx(group,other) cd /media/Storage/project进入我的项目目录 chmod 775 -R app/cache app/logs web/uploads private/uploads – recursion更改可上载目录rwx(owner,group)和rx(other)的文件权限 chmod g+s -R /media/Storage/project – 以recursion的方式为目录中新创build的文件保留用户和组和文件权限