我在这里呆了大约两天,试图弄清楚如何完成这个运行,希望有人能指出我做错的地方。
尝试使用此配置文件在 Nginx-CentOS 6 上运行 Symfony2。
upstream phpfcgi {
server 127.0.0.1:9000;
# server unix:/var/run/php5-fpm.sock; #for PHP-FPM running on UNIX socket
}
server {
listen 80;
server_name symfony2;
root /var/www/project/web;
error_log /var/log/nginx/symfony2.error.log;
access_log /var/log/nginx/symfony2.access.log;
# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app)\.php(/|$) {
include /etc/nginx/fastcgi.conf;
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
从...获取这里,这里和这里。我一直在到处尝试做一些小改动,主要基于这些链接所显示的内容。
我的 php-fpm.d/www.conf 文件是这样的......
[www]
listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 4
pm.min_spare_servers = 4
pm.max_spare_servers = 10
pm.max_requests = 500
request_terminate_timeout = 45
request_slowlog_timeout = 45
slowlog = /var/log/php-fpm/www-slow.log
catch_workers_output = yes
security.limit_extensions = .php .php5
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/nginx/tmp/session_php
我从导航器中获取了臭名昭著的“未指定输入文件。”错误。日志如下...
[/var/log/nginx/symfony2.error.log]
2015/03/13 12:49:59 [error] 14298#0: *1 FastCGI sent in stderr: "Unable to open
primary script: /var/www/project/web/app.php (No such file or directory)" while
reading response header from upstream, client: 192.168.0.132, server: symfony2,
request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host:
"192.168.0.199"
[/var/log/nginx/symfony2.error.log]
[13-Mar-2015 12:49:59] WARNING: [pool www] child 14279 said into stderr:
"ERROR: Unable to open primary script: /var/www/project/web/app.php (No such
file or directory)"
项目位于 /var/www/project 中,并具有以下权限集。根据我所读内容进行了修改这里。
drwxr-sr-x. 5 nginx nginx 4096 mar 10 17:00 app
drwxr-sr-x. 2 nginx nginx 4096 mar 10 17:00 bin
-rwxr-sr-x. 1 nginx nginx 2717 mar 10 17:00 composer.json
-rwxr-sr-x. 1 nginx nginx 100442 mar 10 17:00 composer.lock
drwxr-sr-x. 2 nginx nginx 4096 mar 10 17:00 lib
-rwxr-sr-x. 1 nginx nginx 1065 mar 10 17:00 LICENSE
drwxr-sr-x. 3 nginx nginx 4096 mar 10 17:00 nbproject
-rwxr-sr-x. 1 nginx nginx 5750 mar 10 17:00 README.md
drwxr-sr-x. 3 nginx nginx 4096 mar 10 17:00 src
-rwxr-sr-x. 1 nginx nginx 1308 mar 10 17:00 UPGRADE-2.2.md
-rwxr-sr-x. 1 nginx nginx 1962 mar 10 17:00 UPGRADE-2.3.md
-rwxr-sr-x. 1 nginx nginx 356 mar 10 17:00 UPGRADE-2.4.md
-rwxr-sr-x. 1 nginx nginx 8499 mar 10 17:00 UPGRADE.md
drwxr-sr-x. 3 nginx nginx 4096 mar 10 17:00 web
我已经在 Google 上搜索了很多次,也测试了各种不同的方法,但似乎都不起作用 :S。如果有人有任何想法,我很想知道。提前谢谢。
编辑1 检查 app.php 是否存在...
stat /var/www/project/web/app.php
File: `/var/www/project/web/app.php'
Size: 960 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 7997857 Links: 1
Access: (2755/-rwxr-sr-x) Uid: ( 496/ nginx) Gid: ( 493/ nginx)
Access: 2015-03-11 11:10:15.246469137 +0100
Modify: 2015-03-10 17:00:33.026535520 +0100
Change: 2015-03-13 11:55:52.755828687 +0100
答案1
究竟发生了什么仍然未知,但让我更新我所做的事情,以便也许对将来的某些人有用。
我以为是权限问题,所以我尝试了chmod 777
不同chown nobody:nobody
的配置文件,但同样的错误仍然存在。最后,我尝试了一个没有“symfony 技巧”的简单 nginx 配置文件,这是我在克隆项目代码之前尝试验证 LEMP 是否正确安装的文件。
server {
server_name default;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log;
#if defined in each location directive can be defined diferent root locations.
root /var/www;
location / {
index index.html index.php;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
这样做的目的是查看 nginx 的典型欢迎页面和<?php phpinfo(); ?>
测试页面,以确保 PHP-FastCGI 配置正确。我将默认 nginx 安装中的文件放上去/var/www/
,然后瞧!我成功访问了index.html
,并且info.php
成功了。好的,然后我继续创建一个测试文件夹来放置这些文件,并将它们复制到我的 symfony 项目文件夹中。它看起来像这样...
[root@machine www]# tree -L 2
.
├── 404.html
├── 50x.html
├── test
├── index.html <<<<<
└── info.php <<<<<
├── index.html <<<<<
├── info.php <<<<<
└── project
├── app
├── bin
├── composer.json
├── composer.lock
├── index.html <<<<<
├── info.php <<<<<
├── lib
├── LICENSE
├── nbproject
├── private
├── README.md
├── src
├── UPGRADE-2.2.md
├── UPGRADE-2.3.md
├── UPGRADE-2.4.md
├── UPGRADE.md
├── vendor
└── web
结果是我可以成功访问...
/index.html
/info.php
/test/index.html
/test/info.php但它给了我 /project/index.html /project/info.php
上的相同错误
因此,我继续删除整个文件夹并重新开始,在项目文件夹中正确检查 nginx 的配置,然后 git clone 我的代码。现在一切就绪... 功能齐全。
Nginx 配置文件我现在正在运行......
server {
listen 80;
server_name symfony-project;
access_log /var/log/nginx/symfony2_access.log;
error_log /var/log/nginx/symfony2_error.log;
#if defined in each location directive can be defined diferent root locations.
root /var/www/project/web;
# strip app.php/ prefix if it is present
rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;
location / {
index app_dev.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ ^(.+\.php)(/.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}