duanpu2272
duanpu2272
2017-07-22 12:39

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 doujiebo9849 4年前

    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.

    点赞 评论 复制链接分享
  • dtcrw26206 dtcrw26206 3年前

    Changing cgi.fix_pathinfo as per recommended solution didn't help me on Ubuntu 16. I noticed, that even when the error showed up, the theme or plugin still go installed though.

    What helped me in the end was increasing PHP timeouts to higher value as per this guide. You wrote it didn't help you, but did you raise all the values?

    After I raised max_execution_time in php.ini, request_terminate_timeout in php's www.conf and fastcgi_read_timeout in vhost to 300, I am not getting the warnings anymore.

    点赞 评论 复制链接分享

为你推荐