我已安装了Ngnix服务器,并将其配置为:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = / {
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
我收到这些错误(从我的error.log中复制):
*9 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined variable: confMsg in /usr/share/nginx/html/admin-interface/login.php on line 196" while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /admin-interface/login.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost"
2015/12/16 00:27:37 [错误] 952#0:* 9在stderr中发送FastCGI:" PHP消息:PHP注意:未定义索引:/ usr / share / nginx / html中的用户名第245行的/admin-interface/login.php PHP消息:PHP注意:未定义的索引:第249行和#34; /usr/share/nginx/html/admin-interface/login.php中的用户名;在读取上游时,客户端:127.0.0.1,服务器:localhost,请求:" GET /admin-interface/login.php HTTP / 1.1",上游:" fastcgi:// unix:/ var / run / php5-fpm.sock:",host:" localhost"
我尝试使用Ngnix服务器配置此环境,此环境确实可以使用不同的主机。 我确实在我的php.ini
中更改了cgi.fix_pathinfo = 0我的配置缺少什么?
答案 0 :(得分:4)
这不是错误,它是通知。
脚本/usr/share/nginx/html/admin-interface/login.php
正在访问此时不存在的变量$confMsg
。
您可以更改php.ini
中的错误报告级别(这也会对其他脚本产生影响,并且您不想关闭通知..)或修复脚本中的错误变量访问权限。
第二种解决方案会更容易,因为您只需初始化$confMsg = '';
。
答案 1 :(得分:-1)
我很遗憾地说这个问题太模糊了,很难回答...... 有什么问题??
据我从错误文件中可以看到,这里没有问题。只是PHP通知。
看看这个:
jq -r '.[] | [ .string, .number|tostring ] | join(": ")' <<< '
[{ "number": 9, "string": "nine"},
{ "number": 4, "string": "four"}]
'
nine: 9
four: 4
你能看到什么不对吗?你将/ location包含在错误位置,而不是逻辑我的朋友......你的“/”下的php文件将永远不会传递给php5-fpm。除非我对你的要求一无所知,否则就这样做;
删除;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
向下。
添加此内容:
location = /50x.html {
然后;
location ~ [^/]\.php(/|$) { #open location bracket
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) { #open condition bracket
return 404;
} #close condition bracket
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
} #close location bracket
如果出现问题,请查看打开和关闭括号,因为这似乎是您的克星(您在服务器块中打开了一个括号 - 确保关闭它)。如果全部通过;
sudo nginx -t # to test your config.
请在下次发布代码时,请花一秒钟删除所有垃圾评论。这将帮助您获得答案或至少对您的问题感兴趣。
如果一切顺利,您可以考虑为更强大/更有效的服务器添加这些位置配置;
sudo nginx -s reload
如果您不理解某个设置,请不要添加它。如果不知道它是什么类型,就像盲目地在你的车里加油一样。