A-A+

ubuntu 升级到16.04后nginx显示空页

2016年10月30日 学习随笔, 技术文章 ubuntu 升级到16.04后nginx显示空页已关闭评论 阅读 85 次

手抖抖升级了ubuntu的版本然后悲剧了!!!!!!!!提供的www服务居然显示了大空屏,log没有任何错误!!!疯了!!!

不是不爱国,度娘够垃圾 没结果(后来体会发现没有接受ubuntu的有关nginx升级提示沿用了之前的配置)
不得不爬墙找寻问题的真谛 谷歌真有结果 蓝瘦香菇(md纠结在php5和php7上很久 气人啊)

就把这一行补在nginx.conf或者(/etc/nginx目录自查)对应在enable site的对应配置上即可

 

fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

 

我可以骂人吗??????????????

 

下面是一些参考 请自行了解

Stack Overflow

nginx showing blank PHP pages
I have setup an nginx server with php5-fpm. When I try to load the site I get a blank page with no errors. Html pages are served fine but not php. I tried turning on display_errors in php.ini but no luck. php5-fpm.log is not producing any errors and neither is nginx.

nginx.conf

server {
listen 80;
root /home/mike/www/606club;
index index.php index.html;
server_name mikeglaz.com www.mikeglaz.com;
error_log /var/log/nginx/error.log;
location ~ .php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
EDIT

here's my nginx error log:

2013/03/15 03:52:55 [error] 1020#0: *55 open() "/home/mike/www/606club/robots.txt" failed (2: No such file or directory), client: 199.30.20.40, server: mikeglaz.com, request: "GET /robots.txt HTTP/1.1", host: "mikeglaz.com"
nginx php
shareimprove this question
edited Mar 15 '13 at 4:01
asked Mar 15 '13 at 2:02

mikeglaz
1,70442347
1
Apparently php-fpm was not called by nginx, have you checked error log of nginx? – adamsmith Mar 15 '13 at 2:56

Check my update above. – mikeglaz Mar 15 '13 at 3:36

The nginx error connect() failed ... fastcgi://127.0.0.1:9000contradicts your nginx conf, reload nginx conf? – adamsmith Mar 15 '13 at 3:51

I think this is right. – mikeglaz Mar 15 '13 at 4:01
1
I'm really surprised that this seems only to affect some thousand people on the planet, as even the default nginx+php config causes this thing. – Sliq Apr 29 '14 at 13:07
show 2 more comments
11 Answers
active oldest votes
up vote
106
down vote
accepted
For reference, I am attaching my location block for catching files with the .php extension:

location ~ .php$ {
include /path/to/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
Double-check the /path/to/fastcgi-params, and make sure that it is present and readable by the nginx user.

shareimprove this answer
edited Jan 19 '15 at 15:29

Nitz
21316
answered Mar 15 '13 at 4:34

Julian H. Lam
8,18482964
2
your solution was a part of it. The other part is here wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-??fpm – mikeglaz Mar 15 '13 at 17:12
1
+1 solution worked for me. Cheers! – willdanceforfun Sep 4 '13 at 12:31
65
the last line with 'SCRIPT_FILENAME' did the trick for me 🙂 thanks – Stijn Leenknegt Mar 13 '14 at 22:36
2
thank you, that last line did the trick (it's not needed when using the 1.0 version of nginx that's shipped with Centos). I'd love to see the documentation around all of this improve. – Jorre Mar 27 '14 at 16:23
4
Thx, that last line saved me after hours of googling and changing options – mirkobrankovic Feb 1 '15 at 22:04
show 6 more comments

up vote
213
down vote
replace

include fastcgi_params;
with

include fastcgi.conf;
and remove fastcgi_param SCRIPT_FILENAME ... in nginx.conf

shareimprove this answer
answered Jun 2 '13 at 21:03

spacepille
2,301274
11
This fixed it for me. The .conf has one extra configuration parameter missing from _params. – Malvineous Jul 6 '13 at 4:12
7
This (and, of course, /etc/init.d/nginx restart) also fixed it for me on Debian Testing after an nginx upgrade on 10 September 2014. – severin Sep 10 '14 at 15:46
5
This fixed it for me as well after updating nginx to 1.6.2 (Sept. 2014 update). Gotta love updates that break things randomly. – Mahn Sep 21 '14 at 17:10
12
Here is the backstory of fastcgi_params vs fastcgi.conf: blog.martinfjordvald.com/2013/04/… – Levit Sep 23 '14 at 9:48
3
This code doesn't work - i don't know why; This code works, I don't know why. you saved me several hours. – Alex Jan 27 '15 at 9:23
show 12 more comments
up vote
42
down vote
Also had this issue and finally found the solution here. In short, you need to add the following line to your nginx fastcgi config file (/etc/nginx/fastcgi_params in Ubuntu 12.04)

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
shareimprove this answer
answered Mar 11 '14 at 19:30

Constant Meiring
1,63122344
2
Thank you so much, this fixed it on Ubuntu 12.04 LTS. – Valentin Klinghammer Apr 8 '14 at 10:19
1
Works like a charm! – rafaels88 Aug 12 '14 at 2:27
2
Fixed for me as well after upgrading nginx 1.5.4 -> 1.7.4. Thank you so much! – trisweb Sep 20 '14 at 20:08
4
Worked on Ubuntu 14.04. – Blossoming_Flower Oct 7 '14 at 18:30
1
Thanks, It worked on Freebsd 10 – h4k1m Dec 23 '14 at 18:46
show 5 more comments
up vote
13
down vote
Many users fall in this thread expecting to find a solution for blank pages being displayed while using nginx+php5-fpm, me being one of them. This is a recap of what I ended up doing after reading many of the answers here plus my own investigations:

1) Open /etc/php5/fpm/pool.d/www.conf and check the value of parameter location.

location = /var/run/php5-fpm.sock
2) Parameter location should match fastcgi_pass parameter in your nginx.conf file.

fastcgi_pass unix:/var/run/php5-fpm.sock;
3) Check the file actually exists:

$ file /var/run/php5-fpm.sock
/var/run/php5-fpm.sock: socket
4) If it doesn't exist that means php5-fpm is not running, so you need to restart it:

$ sudo /etc/init.d/php5-fpm restart
[ ok ] Restarting php5-fpm (via systemctl): php5-fpm.service.

With regard to the location section:

location ~ .php$ {
include fastcgi_params;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}
Check the file fastcgi_params exists at location /etc/nginx/:

$ file /etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params: ASCII text
Generally this file contains a list of variable definitions required by php5-fpm:

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
...
fastcgi_param REDIRECT_STATUS 200;
nginx includes two possible parameter files: fastcgi_params and fastcgi.conf. The difference between both is the definition of variable SCRIPT_FILENAME:

$ diff fastcgi_params fastcgi.conf
1a2
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
To make a long story short, fastcgi.conf should always work. If for some reason you're using fastcgi_params, you should define SCRIPT_FILENAME:

location ~ .php$ {
include fastcgi_params;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Now reload nginx configuration:

$ sudo nginx -s reload
And check a php file is displayed correctly. For instance:

/var/www/html/test.php

<pre><?php var_export($_SERVER)?></pre>
Where /var/www/html is the path to the document root.

shareimprove this answer
edited Nov 21 '15 at 23:05
answered Aug 9 '15 at 15:41

Diego Pino
5,4423039

Thanks Diego! fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; Did the trick finally. – danger89 Nov 21 '15 at 22:38

The include fastcgi.conf helped to fix it all – Rytis Luko?evi?ius Dec 1 '15 at 12:02

awesome breakdown! I was missing the SCRIPT_FILENAME config, this made it work – herval Dec 9 '15 at 16:53

I missed the SCRIPT_FILENAME. Works now! Thanks so much for the detailed answer. Very much appreciated. – Venkatapathi Raju M May 17 at 3:48
add a comment
up vote
12
down vote
I wrote a short C program that returns the environment variables passed from nginx to the fastCGI application.

#include <stdlib.h>
#include <fcgi_stdio.h>
extern char **environ;

int main(int argc, char **argv) {
char *envvar;
int i;

int count = 0;
while(FCGI_Accept() >= 0) {
printf("Content-type: text/htmlnn"
"<html><head><title>FastCGI Call Debug Tool</title></head>n"
"<body><h1>FastCGI Call Debugging Tool</h1>n"
"<p>Request number %d running on host <i>%s</i></p>n"
"<h2>Environment Variables</h2><p>n",
++count, getenv("SERVER_NAME"));
i = 0;
envvar = environ[i];
while (envvar != NULL) {
printf("%s<br/>",envvar);
envvar = environ[++i];
}
printf("</p></body></html>n");
}
return 0;
}
Save this to a file, e.g. fcgi_debug.c

To compile it, first install gcc and libfcgi-dev, then run:

gcc -o fcgi_debug fcgi_debug.c -lfcgi
To run it, install spawn-fcgi, then run:

spawn-fcgi -p 3000 -f /path/to/fcgi_debug
Then, change your nginx fcgi config to point to the debug program:

fastcgi_pass 127.0.0.1:3000;
Restart nginx, refresh the page, and you should see all the parameters appear in your browser for you to debug! 🙂

shareimprove this answer
edited Dec 3 '15 at 3:46
answered Oct 29 '14 at 23:49

tudor
314212

Note, you need headers and spawn-fcgi. On Debian/Ubuntu you can get it by apt-get install spawn-fcgi libfcgi-dev. – pevik Nov 20 '15 at 9:26
add a comment
up vote
8
down vote
These hints helped me with my Ubuntu 14.04 LTS install,

In addition I needed to turn on the short_open_tag in /etc/php5/fpm/php.ini

$ sudo kate /etc/php5/fpm/php.ini

short_open_tag = On

$ sudo service php5-fpm restart
$ sudo service nginx reload
shareimprove this answer
edited Jun 25 '15 at 13:11

mariowise
634622
answered May 26 '14 at 16:34

Codename Steeve Knight
15927

This fixed by DO droplet Ubuntu install. Thanks – Andrew Jan 12 '15 at 1:39

This was fixed for me after installing nginx 1.9.4 – Ajeeb.K.P Sep 16 '15 at 12:02

Thanks, again caught by this silly error. – pevik Nov 20 '15 at 9:22
add a comment
up vote
4
down vote
Add this in /etc/nginx/conf.d/default.conf:

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
shareimprove this answer
edited Sep 28 '14 at 5:05

Brad
87.4k22155273
answered Sep 14 '14 at 22:33

nomulex
411
2
Would you mind please providing a bit more detail on what exactly OP's problem is and how your answer solves OP's problem? – wookie919 Sep 14 '14 at 22:38

Problem solved! – Brad Sep 28 '14 at 5:05
1
This solved the same problem for me on Ubuntu 15.04 with nginx 1.8.0 and php-fpm 5.6.4-4ubuntu6. I'd love to know what this is actually doing and why it isn't included with the default nginx config file, but I am at least happy that I've now codified it in a Dockerfile. – James Williams May 31 '15 at 15:21

Putting the value in /etc/nginx/fastcgi_params file would be more proper I think. – Arda Sep 2 '15 at 9:57
add a comment
up vote
3
down vote
Make sure you've got this in /etc/nginx/fastcgi_params

fastcgi_param SCRIPT_FILENAME $request_filename;
Who knows why this isn't there already? The amount of time this must collectively waste!

shareimprove this answer
edited Aug 10 at 7:02
answered Mar 25 at 9:10

Tim
638820
add a comment
up vote
2
down vote
In case anyone is having this issue but none of the above answers solve their problems, I was having this same issue and had the hardest time tracking it down since my config files were correct, my ngnix and php-fpm jobs were running fine, and there were no errors coming through any error logs.

Dumb mistake but I never checked the Short Open Tag variable in my php.ini file which was set to short_open_tag = Off. Since my php files were using <? instead of <?php, the pages were showing up blank. Short Open Tag should have been set to On in my case.

Hope this helps someone.

shareimprove this answer
answered Nov 18 '14 at 19:21

McLovin
187215
add a comment
up vote
0
down vote
None of the above answers worked for me - PHP was properly rendering everything except pages that relied on mysqli, for which it was sending a blank page with a 200 response code and not throwing any errors. As I'm on OS X, the fix was simply

sudo port install php56-mysql

followed by a restart of PHP-FPM and nginx.

I was migrating from an older Apache/PHP setup to nginx, and failed to notice the version mismatch in the driver for php-mysql and php-fpm.

shareimprove this answer
answered Dec 29 '14 at 22:35

jczaplew
955714
add a comment
up vote
0
down vote
The reason this problem occurs is because the fastcgi configurations in nginx do not function as required and in place or processing, they respond as html data. There are two possible ways in which you can configure your nginx to avoid this problem.

Method 1:
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
# With php5-fpm:
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
Method 2:
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include snippets/fastcgi-php.conf;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
Both the methods would work properly, you can go ahead and take any one of them. They almost perform the same operations with a very few difference.

shareimprove this answer
answered May 31 at 6:57

评论已关闭!

Copyright © 理处言语然自 保留所有权利.   Theme  Ality 京ICP备07032740号

用户登录

分享到: