在centos上成功编译安装nginx 1.4、php 5.4并成功启动nginx和php-fpm后,访问php提示"File not found.",同时在错误日志中看到:
代码如下:
2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.168.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.168.133"
错误解决方法:
在Nginx配置文件中找到定义调用脚本文件的地方,如:
代码如下:
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
修改成如下方式($document_root):
代码如下:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
提示:
$document_root 代表当前请求在root指令中指定的值。如:
代码如下:
location / {
root /usr/local/nginx/html;
index index.php index.html index.htm;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
上面配置中的$document_root就是针对/usr/local/nginx/html目录下的php文件进行解析。
之前一直nginx加载的是初始化的html目录,没有加载我指定的项目目录,各种网上查找问题,以为是项目代码问题,又下载了laravel源码测试了下还是那样,修改了php-fpm的加载方式tcp为socket 还是不行
后来我都想下载docker安装环境了,一想下载太慢就放弃了,还好最后调试了出来正常了,直接贴代码吧
server {
listen 80;
server_name www.crm_test.com;
root /app/test/crm/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.(?!well-known).* {
deny all;
}
}