操作系统: Centos7
Nginx: 1.9.14
请考虑这个简单的服务器块
server {
listen 80;
server_name website.com;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我已经在试图弄清楚这个了。以上配置有效。位于root指令的是一个名为index.php的文件,其中包含此行
<?php phpinfo();
假设我想将我的root指令更改为
root /steven/html;
在此位置内,相同的index.php文件驻留。但我得到的不是PHPINFO;
File not found.
我所做的就是更改root指令,因为这是我宁愿放置文件的地方.. /var/log/nginx/error.log 显示;
2016/05/24 04:03:41 [error] 473#473: *7 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 125.238.2.111, server: website.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "website.com"
我知道会问以下内容,所以我会包含这些内容。
从源代码编译的Nginx
nginx version: nginx/1.9.14
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --add-module=/root/custom-nginx/nginx-1.9.14/src/http/modules/ngx_cache_purge/ --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module --without-http_memcached_module --with-openssl=../../openssl-1.0.2g --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'
fastcgi_params的内容
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
完整性检查
[root@ip-172-31-2-48 /]# ls -l /steven/html
total 4
-rw-r--r--. 1 root root 17 May 24 03:49 index.php
答案 0 :(得分:1)
我不常经常回答我自己的问题!是的!
@Darren让我把PHP-FPM的监听端口从默认的9000更改为其他东西。
我试图这样做,但由于某种原因,php-fpm.service不允许它。哦亲爱的..
ERROR: unable to bind listening socket for address '127.0.0.1:9001': Permission denied (13)
我找到了这个。
cat /etc/selinux/config
将 SELINUX =强制执行更改为 SELINUX =已停用
这不仅允许PHP-FPM进程的端口号绑定到9001,而且当我想指定我自己的root指令时,它还修复了找不到文件的问题。
现在可能所有人都遇到文件未找到的问题 - 这就是您需要检查的内容。
再次感谢@Darren,但我从来没有发现过这个。