1

Every hour or so I am starting to get 500 errors on wp-admin and wp-admin/admin-ajax.php in particular. I run DSO + APC + Nginx (admin) + Apache. Apache runs on port 8080 and Nginx on 80.

What I have done so far:

  1. I started looking into debug.log and took care of some fatal crashes that happened from time to time
  2. I added 0 */1 * * * /usr/sbin/tmpwatch -am 1 /tmp/nginx_client because my log was indicating that tmp inodes were all used up and crashed nginx
  3. Inspected other problems and upped PHP memory_limit to 128M
  4. For some reason my wp-admin folder was assigned to the user 1001, which I changed back to nobody:nobody (nginx currently run as nobody)

I am using the following vhosts configuration for the Nginx frontend:

# BEGIN W3TC Page Cache cache
location ~ /wp-content/cache/page_enhanced.*html$ {
    add_header Vary "Accept-Encoding, Cookie";
    add_header Pragma "no-cache";
    add_header Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate";
}
location ~ /wp-content/cache/page_enhanced.*gzip$ {
    gzip off;
    types {}
    default_type text/html;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Pragma "no-cache";
    add_header Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate";
    add_header Content-Encoding gzip;
}
# END W3TC Page Cache cache
# BEGIN W3TC Page Cache core
#set $w3tc_rewrite 1;
set $w3tc_rewrite "";
if ($request_method = POST) {
    set $w3tc_rewrite 0;
}
if ($query_string != "") {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
    set $w3tc_rewrite 0;
}
if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.4)") {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(w3tc_preview)") {
    set $w3tc_rewrite _preview;
}
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite.html$w3tc_enc") {
    set $w3tc_ext .html;
}
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite.xml$w3tc_enc") {
    set $w3tc_ext .xml;
}
if ($w3tc_ext = "") {
  set $w3tc_rewrite 0;
}
#if ($w3tc_rewrite = 1) {
if ($w3tc_rewrite != 0) {
    rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite$w3tc_ext$w3tc_enc" last;
}
# END W3TC Page Cache core

I am excluding wp-admin - possible culprit here?

 # Don't cache uris containing the following segments
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-location$
        set $cache_uri 'null cache';
    }


 location / {
          error_page 405 = @backend;
          add_header X-Cache "HIT from Backend";
          proxy_pass http://backend:8080;
          include proxy.inc;
          include microcache.inc;
          }

Temporary workaround is restarting nginx. I am using a simple nginx.conf.

4
  • Can you post the logs? More than likely their under /var/log/ directory some where... Curious what the 500 is
    – Ethode
    Apr 9, 2015 at 13:00
  • I only have this in my error.log file: 2015/04/09 09:18:09 [warn] 18688#0: conflicting server name "www.domain.com" on 0.0.0.0:80, ignored and the same error but with host IP address. Looks like I will be debugging that now
    – mashup
    Apr 9, 2015 at 18:31
  • I found something on overflow stackoverflow.com/questions/11426087/… - I will try adding the localhost IP directly
    – mashup
    Apr 9, 2015 at 18:36
  • The culprit of that particular conflict was this line in nginx.conf => include "/etc/nginx/vhosts/*"; --- I removed all vhosts except one and I got rid off the conflict. I'll just keep debugging everything I find, might not find the particular cause thou
    – mashup
    Apr 9, 2015 at 18:42

1 Answer 1

1

Although I was unsuccessful in narrowing it down precisely, I want to make an educated guess here.

The most likely things that helped me solve this in order:

  • 1) Upping the memory_limit in PHP config and wp-config.php to 256. You may even try 512, although this may cause other issues. My assumption here is that one of my MySQL queries is very resource-hungry which I had not optimized yet and it might have caused the issue, this was apparent from looking into /mysql/slow.log (you may need turn on slow sql logging first in /etc/my.cnf
  • 2) Turning on debug.log and debugging any critical errors goes without saying
  • 3) Addressing Nginx IP conflicts, check your vhosts
  • 4) Whitelist admin-ajax.php in mod_security (removing some rules) You can google various rules that may be causing issues, although I find it unlikely that it would throw a 502. If it were modsec, it would throw a 403 or 40x

Should I encounter the issue again next few days or I find the root cause I will update it again

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .