Recurring 404 error for all pages (but not posts or bbPress topics)
-
I have been tearing my hair out trying to solve an infuriating bug for the past few weeks, and after gathering as much info about this demon-bug as I can, I’m appealing to any higher powers in this forum to help me squash this. Please help…
The problem:
- Every 1-2 days, Pages of my WordPress site throw a 404 error.
- This seems to affect most/all Pages, but not Posts or forum Topics.
- The homepage, which I understand is also a Page, however, loads fine.
- So far I have been unable to reproduce the issue on demand, but it has been reliably cropping up every 1-2 days as mentioned.
Temporary solution: This seems to be temporarily resolved by simply clicking to Settings > Permalinks. I don’t need to actually DO anything at the permalinks settings menu, it seems that just clicking to it is somehow enough. However, the 404 errors come back again after 1-2 days.
Solutions researched / tried so far:
- Google searches usually suggest .htaccess edits, but I’m on an Nginx server so I’m not sure if .htaccess solutions are still relevant since Nginx supposedly doesn’t use them…?
- Googling permalinks nginx issues suggests to modify Nginx try_files to
try_files $uri $uri/ /index.php?$args;
, e.g. solution #2 here. I have tried this, but it does not seem to help. - Disabling and enabling plugins does not seem to work, although I’m finding it difficult to definitively debug as I have to wait 1-2 days for the issue to crop up.
Possible relevant information:
Server setup: Linux [Ubuntu 20.04] + Nginx [1.18.0] + Mariadb [10.3.25] + PHP [7.4.3]
I’m using the Post Name permalink structure for my posts, e.g. https://DOMAIN.com/sample-post/
My .htaccess is as follows:
# BEGIN WP Rocket v3.8.3 # Use UTF-8 encoding for anything served text/plain or text/html AddDefaultCharset UTF-8 # Force UTF-8 for a number of file formats <IfModule mod_mime.c> AddCharset UTF-8 .atom .css .js .json .rss .vtt .xml </IfModule> # FileETag None is not enough for every server. <IfModule mod_headers.c> Header unset ETag </IfModule> # Since we’re sending far-future expires, we don’t need ETags for static content. # developer.yahoo.com/performance/rules.html#etags FileETag None <IfModule mod_alias.c> <FilesMatch "\.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$"> <IfModule mod_headers.c> Header set X-Powered-By "WP Rocket/3.8.3" Header unset Pragma Header append Cache-Control "public" Header unset Last-Modified </IfModule> </FilesMatch> <FilesMatch "\.(css|htc|js|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$"> <IfModule mod_headers.c> Header unset Pragma Header append Cache-Control "public" </IfModule> </FilesMatch> </IfModule> # Expires headers (for better cache control) <IfModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 1 month" # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5) ExpiresByType text/cache-manifest "access plus 0 seconds" # Your document html ExpiresByType text/html "access plus 0 seconds" # Data ExpiresByType text/xml "access plus 0 seconds" ExpiresByType application/xml "access plus 0 seconds" ExpiresByType application/json "access plus 0 seconds" # Feed ExpiresByType application/rss+xml "access plus 1 hour" ExpiresByType application/atom+xml "access plus 1 hour" # Favicon (cannot be renamed) ExpiresByType image/x-icon "access plus 1 week" # Media: images, video, audio ExpiresByType image/gif "access plus 4 months" ExpiresByType image/png "access plus 4 months" ExpiresByType image/jpeg "access plus 4 months" ExpiresByType image/webp "access plus 4 months" ExpiresByType video/ogg "access plus 4 months" ExpiresByType audio/ogg "access plus 4 months" ExpiresByType video/mp4 "access plus 4 months" ExpiresByType video/webm "access plus 4 months" # HTC files (css3pie) ExpiresByType text/x-component "access plus 1 month" # Webfonts ExpiresByType font/ttf "access plus 4 months" ExpiresByType font/otf "access plus 4 months" ExpiresByType font/woff "access plus 4 months" ExpiresByType font/woff2 "access plus 4 months" ExpiresByType image/svg+xml "access plus 1 month" ExpiresByType application/vnd.ms-fontobject "access plus 1 month" # CSS and JavaScript ExpiresByType text/css "access plus 1 year" ExpiresByType application/javascript "access plus 1 year" </IfModule> # Gzip compression <IfModule mod_deflate.c> # Active compression SetOutputFilter DEFLATE # Force deflate for mangled headers <IfModule mod_setenvif.c> <IfModule mod_headers.c> SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding # Don’t compress images and other uncompressible content SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|swf|mp?g|mp4|webm|webp|pdf)$ no-gzip dont-vary </IfModule> </IfModule> # Compress all output labeled with one of the following MIME-types <IfModule mod_filter.c> AddOutputFilterByType DEFLATE application/atom+xml \ application/javascript \ application/json \ application/rss+xml \ application/vnd.ms-fontobject \ application/x-font-ttf \ application/xhtml+xml \ application/xml \ font/opentype \ image/svg+xml \ image/x-icon \ text/css \ text/html \ text/plain \ text/x-component \ text/xml </IfModule> <IfModule mod_headers.c> Header append Vary: Accept-Encoding </IfModule> </IfModule> # END WP Rocket RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # BEGIN WordPress # The directives (lines) between "BEGIN WordPress" and "END WordPress" are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. <IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress # php -- BEGIN cPanel-generated handler, do not edit # Set the “ea-php74” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php74 .php .php7 .phtml </IfModule> # php -- END cPanel-generated handler, do not edit # BEGIN cPanel-generated php ini directives, do not edit # Manual editing of this file may result in unexpected behavior. # To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor) # For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI) <IfModule php7_module> php_flag display_errors Off php_value max_execution_time 30 php_value max_input_time 60 php_value max_input_vars 1000 php_value memory_limit 512M php_value post_max_size 260M php_value session.gc_maxlifetime 1440 php_value session.save_path "/var/cpanel/php/sessions/ea-php74" php_value upload_max_filesize 256M php_flag zlib.output_compression Off </IfModule> <IfModule lsapi_module> php_flag display_errors Off php_value max_execution_time 30 php_value max_input_time 60 php_value max_input_vars 1000 php_value memory_limit 512M php_value post_max_size 260M php_value session.gc_maxlifetime 1440 php_value session.save_path "/var/cpanel/php/sessions/ea-php74" php_value upload_max_filesize 256M php_flag zlib.output_compression Off </IfModule> # END cPanel-generated php ini directives, do not edit Options -Indexes
In my server, /etc/nginx/sites-enabled/300h.conf yields:
server { server_name go.DOMAIN.com DOMAIN.com www.DOMAIN.com; root /var/www/html; index index.php; charset UTF-8; client_max_body_size 128m; ## # gzip config ## add_header Strict-Transport-Security "max-age=31536000"; brotli on; brotli_comp_level 6; brotli_types text/xml image/svg+xml application/x-font-ttf image/vnd.microsoft.icon application/x-font-opentype application/json font/eot application/vnd.ms-fontobject application/javascript font/otf application/xml application/xhtml+xml text/javascript application/x-javascript text/plain application/x-font-truetype application/xml+rss image/x-icon font/opentype text/css image/x-win-bitmap; # if ($http_host = "ask.DOMAIN.com") { # rewrite ^ https://forum.DOMAIN.com permanent; # } # if ($http_host = "forum.DOMAIN.com") { # rewrite ^/(.*)$^ https://DOMAIN.com/forum/$1 permanent; # } #Yoast SEO Sitemaps location ~ ([^/]*)sitemap(.*).x(m|s)l$ { ## this rewrites sitemap.xml to /sitemap_index.xml rewrite ^/sitemap.xml$ /sitemap_index.xml permanent; ## this makes the XML sitemaps work rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?yoast-sitemap-xsl=$1 last; rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last; rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last; ## The following lines are optional for the premium extensions ## News SEO rewrite ^/news-sitemap.xml$ /index.php?sitemap=wpseo_news last; ## Local SEO rewrite ^/locations.kml$ /index.php?sitemap=wpseo_local_kml last; rewrite ^/geo-sitemap.xml$ /index.php?sitemap=wpseo_local last; ## Video SEO rewrite ^/video-sitemap.xsl$ /index.php?yoast-sitemap-xsl=video last; } gzip on; gzip_static on; gzip_vary on; gzip_disable "msie6"; gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; gzip_http_version 1.1; gzip_comp_level 6; gzip_proxied any; ## # Server log config ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log warn; ## # FastCGI cache exceptions ## set $no_cache 0; set $cache_uri $request_uri; if ($request_method = POST) { set $cache_uri "null cache"; set $no_cache 1; } if ($query_string != "") { set $cache_uri "null cache"; set $no_cache 1; } 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-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { set $cache_uri "null cache"; set $no_cache 1; } if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") { set $cache_uri "null cache"; set $no_cache 1; } ## # Browser cache config ## location ~ \.(css|htc|js|js2|js3|js4)$ { expires max; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; } location ~ \.(html|htm|rtf|rtx|svgz|txt|xsd|xsl|xml)$ { try_files $uri $uri/ /index.php?q=$uri&$args; expires 3600s; add_header Pragma "public"; add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate"; } location ~ \.(webp|woff2|woff|asf|asx|wax|svg|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ { expires max; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; log_not_found off; } ## # Favicon ## location = /favicon.ico { log_not_found off; access_log off; } ## # robots.txt ## location = /robots.txt { allow all; log_not_found off; access_log off; } ## # Deny access to hidden files ## location ~ /\. { deny all; } ## # Deny access to uploaded PHP files ## # location ~* /(?:uploads|files)/.*\.php$ { deny all; } ## # Deny access to WordPress include-only files ## location ~ ^/wp-admin/includes/ { deny all; } location ~ ^/wp-includes/[^/]+\.php$ { deny all; } location ~ ^/wp-includes/js/tinymce/langs/.+\.php { deny all; } location ~ ^/wp-includes/theme-compat/ { deny all; } location / { # try_files $uri $uri/ /index.php?q=$uri&$args; try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; # fastcgi_intercept_errors on; # fastcgi_keep_conn on; # fastcgi_read_timeout 300; # fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:run/php/php7.4-fpm.sock; ## # FastCGI cache config ## # fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:10m max_size=1000m inactive=60m; # fastcgi_cache_key $scheme$host$request_uri$request_method; # fastcgi_cache_use_stale updating error timeout invalid_header http_500; # fastcgi_no_cache $no_cache; # fastcgi_cache_bypass $no_cache; # fastcgi_cache WORDPRESS; #fastcgi_cache_valid any 30m; } listen 443 ssl http2; # managed by Certbot ssl_certificate /etc/letsencrypt/live/DOMAIN.com-0001/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/DOMAIN.com-0001/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { server_name ask.DOMAIN.com; return 301 https://DOMAIN.com/forum$request_uri; listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/DOMAIN.com-0001/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/DOMAIN.com-0001/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { server_name forum.DOMAIN.com; return 301 https://DOMAIN.com/forum$request_uri; listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/DOMAIN.com-0001/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/DOMAIN.com-0001/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { if ($host = www.DOMAIN.com) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = go.DOMAIN.com) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = DOMAIN.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name go.DOMAIN.com DOMAIN.com www.DOMAIN.com; return 404; # managed by Certbot } server { if ($host = ask.DOMAIN.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name ask.DOMAIN.com; return 404; # managed by Certbot } server { if ($host = forum.DOMAIN.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name forum.DOMAIN.com; return 404; # managed by Certbot }
The page I need help with: [log in to see the link]
- The topic ‘Recurring 404 error for all pages (but not posts or bbPress topics)’ is closed to new replies.