duanpu2272 2017-07-22 12:39
浏览 226
已采纳

wordpress报告504安装主题/插件时的网关超时(nginx)

Problem: I'm using wordpress on LNMP environment. My site works just fine, but when installing themes / plugins, it does not work and reports a 504 error.

Bottom line:

  1. Nginx and php (at least sometimes) communicate fine, since I can see my site display normally.
  2. FTP host, user name and password are correct, since when installing themes or plugins, (at least some) files are downloaded into theme or plugin folder (but not the whole theme or plugin).
  3. FTP user and Nginx user do have permission to access to the folder, which is owned by FTP user. (FTP & Nginx users are in same group and the folder is set to 775)
  4. i tried bigger fastcgi_read_timeout values (e.g. 300), but it did not help.

Details When I run into the problem, I did what people normally do. I went to GOOGLE and set fastcgi_read_timeout to bigger values, as I remember this worked for me on other severs. This, however, only have me wait for 5 min before get the error report (300 s = 5 min). I also tried bigger fastcgi_buffer_size, which also did not work. I think this has something to do with installing theme or plugin, since the web page itself displays fine and error only occurs when installing.When installation failed, I find (not complete plugin) files in plugin folder.

Nginx error log:

 2017/07/22 07:42:26 [error] 2672#2672: *283 upstream timed out (110:
 Connection timed out) while reading response header from upstream,
 client: my.client.ip.adderss, server: name.of_my_server, request:
 "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream:
 "fastcgi://127.0.0.1:9000", host: "name.of_my_server", referrer:
 "http://my.domain/wp-admin/plugin-install.php?s=best+CAPTCHA&tab=search&type=term"

(There are many entries similar to this one.)

Interestingly, wordpress displays error as:

Installation failed: 504 Gateway Time-out 504 Gateway Time-out
nginx/1.10.3 (Ubuntu) <!-- a padding to disable MSIE and Chrome
friendly error page --> <!-- a padding to disable MSIE and Chrome
friendly error page --> <!-- a padding to disable MSIE and Chrome
friendly error page --> <!-- a padding to disable MSIE and Chrome
friendly error page --> <!-- a padding to disable MSIE and Chrome
friendly error page --> <!-- a padding to disable MSIE and Chrome
friendly error page -->

Half of that message certainly should not be shown. Perhaps there is something wrong here.

php-fpm's log shows no error, neither does wordpress' log when enabling logging.

software versions

  • nginx 1.10.3
  • mysql Ver 14.14 Distrib 5.7.19
  • PHP 7.0.18-0ubuntu0.16.04.1
  • wordpress 4.8
  • Ubuntu 16.04.2 LTS

Any thoughts?

  • 写回答

2条回答 默认 最新

  • doujiebo9849 2017-07-25 12:11
    关注

    This issue is caused by setting cgi.fix_pathinfo to 0 in php.ini.The intention was to reduce security risks, but it can cause more problems.

    cgi.fix_pathinfo = 1
    

    Basically setting cgi.fix_pathinfo to 1 (leaving it as default) solved the problem, for correct and secure nginx + php-fpm configure, please see "PHP FastCGI Example". I also posted an article on my blog regarding how to solve the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?