我正在运行php-cgi和NGINX。它们在一个文件夹中运行,但是其根目录在其中2个目录中,而在其中2个目录中。当根是html(默认值)时,它们可以正常工作,但是现在php报告“未指定输入文件”错误。我尝试设置目录以完全控制所有程序,我已经拥有完全控制权,我尝试查看php是否在其他目录中查找,尝试更改目录,对php变量进行硬编码等。已经按照有关如何解决此问题的5种不同的教程进行了介绍,但没有一个解决方案。控制台中没有错误,并且我的fastcgi.conf保持不变。php和NGINX都可以正常运行并且可以通信,但是php由于某种原因无法获取文件。访问任何非PHP文件时,NGINX成功检索了文件,我的浏览器显示了该文件。我已经使用netstat验证了,唯一监听9100端口的是我的php-cgi。而且,唯一监听8080端口的是NGINX。php和NGINX均配置为正确通信,并且php-cgi通过php目录中的RunHiddenConsole.exe运行。
这是目录树,格式类似于YAML:
EclipsePHP
- Code
- Blog
- Source (NGINX/php root Location/Website Source Files)
- NGINX
- 1.9.11 (NGINX Executable Location)
- php (php Executable Location)
还有我的nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
client_max_body_size 5G;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
root ../../Code/Blog/Source;
client_max_body_size 5G;
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.php;
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
client_max_body_size 5G;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
recursive_error_pages off;
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
client_max_body_size 5G;
try_files $uri =404;
include fastcgi.conf;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9100;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
什么可能是造成此错误的原因,如何解决该错误,以便可以在浏览器中正确查看php文件?(我正在使用Eclipse PHP编辑源代码,无论是否运行Eclipse,都会发生该错误。)
由于php不喜欢相对目录,因此我的解决方案是在每次启动时使用批处理设置绝对目录。在启动NGINX之前,我在批处理启动脚本中插入了以下内容。
set TEXT_FILE=conf\phploc.conf
set REL_PATH=..\..\Code\Blog\Source
set ABS_PATH=
pushd %REL_PATH%
set ABS_PATH=%CD%
popd
echo fastcgi_param SCRIPT_FILENAME %ABS_PATH%$fastcgi_script_name; > %TEXT_FILE%
然后,在NGINX配置文件中,我将以下内容插入php位置块以加载目录设置。
include phploc.conf;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句