SatelliteWP / rocket-nginx

Rocket-Nginx is a Nginx configuration that makes WP-Rocket even faster by serving static pages directly without loading WordPress or PHP.
MIT License
579 stars 129 forks source link

rocket-nginx 404 Not Found #140

Closed fredddie91 closed 4 years ago

fredddie91 commented 4 years ago

Hello, Thanks for the project. I wonder if you could provide a suggestion on the following. I installed the Rocket-Nginx script, and when I activate it, I get a 404 Not Found error across the entire site except the home page. To correct the problem, I have no idea.

WordPress is setup in /usr/share/nginx/html folder.

Here is a sample output of my error log when I Activate rocket-nginx

sudo tail -n 20 /var/log/nginx/error.log 2020/09/22 21:01:27 [crit] 658#658: cache file "/etc/nginx/cache/d/a0/f4fd9a35f749cc5339da1b2430c79a0d" is too small 2020/09/22 23:02:11 [notice] 3087#3087: signal process started 2020/09/22 23:02:14 [error] 3088#3088: 2495 "/usr/share/nginx/html/tag/flip-saunders/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: _, request: "GET /tag/flip-saunders/ HTTP/1.0", host: "www.whodiedtoday.com" 2020/09/22 23:02:15 [error] 3088#3088: 2496 open() "/usr/share/nginx/html/sharon-jones-60-died-american-singer-sharon-jones-the-dap-kingsfuneral-function" failed (2: No such file or directory), client: 192.168.0.124, server: , request: "GET /sharon-jones-60-died-american-singer-sharon-jones-the-dap-kingsfuneral-function HTTP/1.0", host: "www.whodiedtoday.com" 2020/09/22 23:02:18 [error] 3088#3088: *2497 "/usr/share/nginx/html/veteran-actor-orson-bean-dead-at-91-kill-by-a-car/index.php" is not found (2: No such file or directory), client: 192.168.0.104, server: , request: "HEAD /veteran-actor-orson-bean-dead-at-91-kill-by-a-car/ HTTP/1.0", host: "www.whodiedtoday.com" 2020/09/22 23:02:18 [error] 3088#3088: 2498 "/usr/share/nginx/html/veteran-actor-orson-bean-dead-at-91-kill-by-a-car/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: _, request: "GET /veteran-actor-orson-bean-dead-at-91-kill-by-a-car/ HTTP/1.0", host: "www.whodiedtoday.com" 2020/09/22 23:02:19 [error] 3088#3088: 2499 "/usr/share/nginx/html/tag/john-garfield/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: , request: "GET /tag/john-garfield/ HTTP/1.0", host: "whodiedtoday.com" 2020/09/22 23:02:44 [error] 3088#3088: *2500 "/usr/share/nginx/html/tag/florida/index.php" is not found (2: No such file or directory), client: 192.168.0.144, server: , request: "GET /tag/florida/ HTTP/1.0", host: "www.whodiedtoday.com" 2020/09/22 23:02:45 [error] 3088#3088: 2501 "/usr/share/nginx/html/tag/john-ritter/index.php" is not found (2: No such file or directory), client: 192.168.0.1044, server: _, request: "GET /tag/john-ritter/ HTTP/1.0", host: "whodiedtoday.com" 2020/09/22 23:02:59 [error] 3088#3088: 2503 "/usr/share/nginx/html/tag/florida/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: , request: "GET /tag/florida/ HTTP/1.0", host: "www.whodiedtoday.com" 2020/09/22 23:03:03 [error] 3088#3088: *2504 "/usr/share/nginx/html/tag/jon-erik-hexum/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: , request: "GET /tag/jon-erik-hexum/ HTTP/1.0", host: "whodiedtoday.com" 2020/09/22 23:03:10 [error] 3088#3088: 2505 "/usr/share/nginx/html/tag/foreign-relations-of-france/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: _, request: "GET /tag/foreign-relations-of-france/ HTTP/1.0", host: "www.whodiedtoday.com" 2020/09/22 23:03:28 [error] 3088#3088: 2507 "/usr/share/nginx/html/who-important-died-today/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: , request: "GET /who-important-died-today/ HTTP/1.0", host: "www.whodiedtoday.com", referrer: "https://www.whodiedtoday.com/" 2020/09/22 23:03:29 [error] 3088#3088: *2508 "/usr/share/nginx/html/tag/joseph-rotman/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: , request: "GET /tag/joseph-rotman/ HTTP/1.0", host: "whodiedtoday.com" 2020/09/22 23:03:31 [error] 3088#3088: *2509 "/usr/share/nginx/html/tag/foreign-relations-of-france/feed/index.php" is not found (2: No such file or directory), client: 192.168.0.124, server: _, request: "GET /tag/foreign-relations-of-france/feed/ HTTP/1.0", host: "www.whodiedtoday.com"

Thanks Fred

maximejobin commented 4 years ago

I'm not sure what you did exactly but Rocket-Nginx serves the file directly only if it is found. Otherwise, it serves nothing.

Can you post your configuration file (where you included Rocket-Nginx) and also the generated Rocket-Nginx file?

What version of WordPress and WP Rocket are you using?

fredddie91 commented 4 years ago

Thanks for the response. Wordpress version 5.5.1, || and WP Rocket Version 3.7.1.1

If I call rocket-nginx like this nothing happens:

server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /usr/share/nginx/html/;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
try_files "/wp-content/cache/wp-rocket/$host/index.html" $uri $uri/ /index.php$is_args$args;
#  try_files $uri $uri/ /index.php$is_args$args;
}
# Rocket-Nginx configuration
 include rocket-nginx/whodiedtoday.com.conf;
# Newly added fastcgi
    set $skip_cache 0;

2: When I call it in the following example like in the tutorial, that when rocket-nginx becomes active and I have the error.

server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /usr/share/nginx/html/;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
try_files "/wp-content/cache/wp-rocket/$host/index.html" $uri $uri/ /index.php$is_args$args;
#  try_files $uri $uri/ /index.php$is_args$args;
# Rocket-Nginx configuration
 include rocket-nginx/whodiedtoday.com.conf;
}

# Newly added fastcgi
    set $skip_cache 0;

Here is my configuration file and the generated Rocket-Nginx:

server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /usr/share/nginx/html/;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
try_files "/wp-content/cache/wp-rocket/$host/index.html" $uri $uri/ /index.php$is_args$args;
#  try_files $uri $uri/ /index.php$is_args$args;
# Rocket-Nginx configuration
 include rocket-nginx/whodiedtoday.com.conf;
}

# Newly added fastcgi
    set $skip_cache 0;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
    set $skip_cache 1;
}
if ($query_string != "") {
    set $skip_cache 1;
}

# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|^/feed/*|/tag/.*/feed/*|index.php|/.*sitemap.*\.(xml|xsl)") {
    set $skip_cache 1;
}

# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    set $skip_cache 1;
}

if ($remote_addr ~* "24.143.188.139|24.143.188.138") {
     set $skip_cache 1;
}
##
  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
    # newly added fastcgi
fastcgi_cache phpcache;
fastcgi_cache_valid 200 301 302 60m;
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
add_header X-FastCGI-Cache $upstream_cache_status;

  }

 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

llllllllllllllllllllllllllllllllllllllllllllllll

cat /etc/nginx/rocket-nginx/whodied.conf

###################################################################################################
# Rocket-Nginx
#
# Rocket-Nginx is an NGINX configuration to speed up your WordPress
# website with the cache plugin WP-Rocket (http://wp-rocket.me)
#
# Author: Maxime Jobin
# URL: https://github.com/maximejobin/rocket-nginx
#
# Tested with WP-Rocket version: 3.6.0.1
# Tested with NGINX: 1.19 (mainline)
#
# Version 2.1.1
#
###################################################################################################

# Add debug information into header
set $rocket_debug 1;

###################################################################################################
# Do not alter these values
#
set $rocket_bypass 1;               # Should NGINX bypass WordPress and call cache file directly ?
set $rocket_encryption "";          # Is GZIP accepted by client ?
set $rocket_file "";                # Filename to use
set $rocket_is_bypassed "No";       # Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Serving-Static
set $rocket_reason "";              # Reason why cache file was not used. If cache file is used, what file was used
set $rocket_https_prefix "";        # HTTPS prefix to use when cached files are using HTTPS
set $rocket_hsts 0;                 # Is HSTS is off (0) by default. Will be turned on (1) if request is HTTPS

# HSTS value
set $rocket_hsts_value "max-age=31536000; includeSubDomains";

###################################################################################################
# PAGE CACHE
#

# Is GZIP accepted by client ?
if ($http_accept_encoding ~ gzip) {
    set $rocket_encryption "_gzip";
}

# Is Brotli accepted by client ?
if ($http_accept_encoding ~ br) {
    set $rocket_encryption "";
}

# Is SSL request ?
if ($https = "on") {
    set $rocket_https_prefix "-https";
    set $rocket_hsts 1;
}

# If HSTS is disabled, unset HSTS set for Rocket-Nginx configuration
if ($rocket_hsts = "0") {
    set $rocket_hsts_value "";
}

# File/URL to return IF we must bypass WordPress
# Desktop: index.html or index-https.html
# Mobile:  index-mobile.html or index-mobile-https.html
set $rocket_end "/cache/wp-rocket/$http_host/$request_uri/index$rocket_https_prefix.html$rocket_encryption";
set $rocket_url "/wp-content$rocket_end";
set $rocket_file "$document_root/wp-content$rocket_end";
set $rocket_mobile_detection "$document_root/wp-content/cache/wp-rocket/$http_host/$request_uri/.mobile-active";

# Do not bypass if it's a POST request
if ($request_method = POST) {
    set $rocket_bypass 0;
    set $rocket_reason "POST request";
}

# Do not bypass if arguments are found (e.g. ?page=2)
if ($is_args) {
    set $rocket_bypass 0;
    set $rocket_reason "Arguments found";
}

# Do not bypass if the site is in maintenance mode
if (-f "$document_root/.maintenance") {
    set $rocket_bypass 0;
    set $rocket_reason "Maintenance mode";
}

# Do not bypass if one of those cookie if found
# wordpress_logged_in_[hash] : When a user is logged in, this cookie is created (we'd rather let WP-Rocket handle that)
# wp-postpass_[hash] : When a protected post requires a password, this cookie is created.
if ($http_cookie ~* "(wordpress_logged_in_|wp\-postpass_|woocommerce_items_in_cart|woocommerce_cart_hash|wptouch_switch_toogle|comment_author_|comment_author_email_)") {
    set $rocket_bypass 0;
    set $rocket_reason "Cookie";
}

if (-f "$rocket_mobile_detection") {
    set $rocket_bypass 0;
    set $rocket_reason "Specific mobile cache activated";   
}

# Do not bypass if the cached file does not exist
if (!-f "$rocket_file") {
    set $rocket_bypass 0;
    set $rocket_reason "File not cached";
}

# If the bypass token is still on, let's bypass WordPress with the cached URL
if ($rocket_bypass = 1) {
    set $rocket_is_bypassed "Yes";
    set $rocket_reason "$rocket_url";
}

# Clear variables if debug is not needed
if ($rocket_debug = 0) {
    set $rocket_reason "";
    set $rocket_file "";
}

# If the bypass token is still on, rewrite according to the file linked to the request
if ($rocket_bypass = 1) {
    rewrite .* "$rocket_url" last;
}

# Add header to HTML cached files
location ~ /wp-content/cache/wp-rocket/.*html$ {
    etag on;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Cache-Control "no-cache, no-store, must-revalidate";
    add_header X-Rocket-Nginx-Serving-Static $rocket_is_bypassed;
    add_header X-Rocket-Nginx-Reason $rocket_reason;
    add_header X-Rocket-Nginx-File $rocket_file;
    add_header Strict-Transport-Security "$rocket_hsts_value";

}

# Do not gzip cached files that are already gzipped
location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
    etag on;
    gzip off;
    types {}
    default_type text/html;
    add_header Content-Encoding gzip;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Cache-Control "no-cache, no-store, must-revalidate";
    add_header X-Rocket-Nginx-Serving-Static $rocket_is_bypassed;
    add_header X-Rocket-Nginx-Reason $rocket_reason;
    add_header X-Rocket-Nginx-File $rocket_file;
    add_header Strict-Transport-Security "$rocket_hsts_value";

}

# Debug header (when file is not cached)
add_header X-Rocket-Nginx-Serving-Static $rocket_is_bypassed;
add_header X-Rocket-Nginx-Reason $rocket_reason;
add_header X-Rocket-Nginx-File $rocket_file;

# No HSTS header added here. We suppose it's correctly added in the site configuration.

###################################################################################################
# BROWSER CSS CACHE
#
location ~* \.css$ {
    etag on;
    gzip_vary on;
    expires 30d;

}

###################################################################################################
# BROWSER JS CACHE
#
location ~* \.js$ {
    etag on;
    gzip_vary on;
    expires 30d;

}

###################################################################################################
# BROWSER MEDIA CACHE
#
location ~* \.(ico|gif|jpe?g|png|svg|eot|otf|woff|woff2|ttf|ogg)$ {
    etag on;
    expires 30d;

}
maximejobin commented 4 years ago

It seems like you are using multiple scripts at the same time to do caching.

I don't understand why you changed the "try_files".

Also, the include shouldn't be inserted inside location. Please follow our documentation.

It looks like you have a lot going on in your configuration file. You'll need a good cleanup.