Support » Plugin: WP-FFPC » NGiNX 404's

  • Resolved athalas

    (@athalas)


    Hi,

    I’m currently retesting your latest release.

    I’ve activated Memcached server with Memcached extansion + NGiNX, but all my pages are 404’ing apart from the homepage.

    Could you possibly paste a full working nginx configuration?

    If I change $request_uri to $is_args$args my pages load but not getting any cache hits.

    http://wordpress.org/extend/plugins/wp-ffpc/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author petermolnar

    (@cadeyrn)

    Hi athalas,

    Could you please send me the whole nginx configuration?
    It’s hard to tell what’s wrong with it without seeing it 🙂

    Thanks for the promp reply,

    Here it is:

    server {
    listen 88;
    server_name test.site.com;
    root /var/www/test.site.com/;
    index index.php;

    location @memcached {
    default_type text/html;
    set $memcached_key data-test-$scheme://$host$request_uri;
    set $memcached_request 1;

    # exceptions
    # avoid cache serve of POST requests
    if ($request_method = POST ) {
    set $memcached_request 0;
    }
    # avoid cache serve of wp-admin-like pages, starting with “wp-“
    if ( $uri ~ “/wp-” ) {
    set $memcached_request 0;
    }
    # avoid cache for logged in users
    if ($http_cookie ~* “comment_author_|wordpressuser_|wp-postpass_” ) {
    set $memcached_request 0;
    }
    if ( $memcached_request = 1) {
    memcached_pass memcached-servers;
    error_page 404 = @rewrites;
    }

    if ( $memcached_request = 0) {
    rewrite ^ /index.php$request_uri last;
    }
    }

    ## rewrite rules
    location @rewrites {
    rewrite ^ /index.php$request_uri last;
    }

    location ~ .php$ {
    try_files $uri =404;
    fastcgi_index index.php;
    fastcgi_pass php;
    fastcgi_keep_conn on;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

    and also my fastcgi_params:

    fastcgi_connect_timeout 600;
    fastcgi_send_timeout 1800;
    fastcgi_read_timeout 14400;
    fastcgi_buffer_size 256k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;

    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;

    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT $document_root;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param HTTPS $https if_not_empty;

    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;

    # PHP only, required if PHP was built with –enable-force-cgi-redirect
    fastcgi_param REDIRECT_STATUS 200;

    Plugin Author petermolnar

    (@cadeyrn)

    I’ll set up a test environment to see if I can reproduce ( I’ll try to do so tomorrow ), and I’ll get back with the results.

    Plugin Author petermolnar

    (@cadeyrn)

    Hi,

    remove the line
    try_files $uri =404;
    from location ~ .php$ { block, that solved for me.

    I’ve removed it but still getting the 404’s on all pages (accept home)

    server {
    listen 88;
    server_name test.site.com;
    root /var/www/test.site.com/;
    index index.php;

    location @memcached {
    default_type text/html;
    set $memcached_key data-hayibo-$scheme://$host$request_uri;
    set $memcached_request 1;

    # exceptions
    # avoid cache serve of POST requests
    if ($request_method = POST ) {
    set $memcached_request 0;
    }
    # avoid cache serve of wp-admin-like pages, starting with “wp-“
    if ( $uri ~ “/wp-” ) {
    set $memcached_request 0;
    }
    # avoid cache for logged in users
    if ($http_cookie ~* “comment_author_|wordpressuser_|wp-postpass_” ) {
    set $memcached_request 0;
    }

    if ( $memcached_request = 1) {
    memcached_pass memcached-servers;
    error_page 404 = @rewrites;
    }

    if ( $memcached_request = 0) {
    rewrite ^ /index.php$request_uri last;
    }
    }

    ## rewrite rules
    location @rewrites {
    rewrite ^ /index.php$request_uri last;
    }

    location / {
    try_files $uri $uri/ @memcached;
    }

    location ~ .php$ {
    fastcgi_index index.php;
    fastcgi_pass php;
    fastcgi_keep_conn on;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    }

    Hello! congratulations, this plugin is great! However I have the same issue, tryed different config. comment try_files $uri = 404 do not work for me (and I read that creates a security problem related to static files containing) the only page that work is the index, and it is served by php (no debug header found):

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location @memcached {
    default_type text/html;
    set $memcached_key data-$scheme://$host$request_uri;
    set $memcached_request 1;

    # exceptions
    # avoid cache serve of POST requests
    if ($request_method = POST ) {
    set $memcached_request 0;
    }
    # avoid cache serve of wp-admin-like pages, starting with “wp-“
    if ( $uri ~ “/wp-” ) {
    set $memcached_request 0;
    }
    # avoid cache for logged in users
    if ($http_cookie ~* “comment_author_|wordpressuser_|wp-postpass_” ) {
    set $memcached_request 0;
    }

    if ( $memcached_request = 1) {
    memcached_pass memcached;
    error_page = 404 @rewrites;
    }

    if ( $memcached_request = 0) {
    rewrite ^ $request_uri last;
    }
    }

    ## rewrite rules
    location @rewrites {
    rewrite ^ /index.php$request_uri last;
    }

    location ~ \.php$ {
    try_files $uri = 404;
    fastcgi_index index.php;
    fastcgi_pass php5-fpm-sock;
    fastcgi_send_timeout 30;
    fastcgi_read_timeout 30;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    # Some basic cache-control for static files to be sent to the browser
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control “public, must-revalidate, proxy-revalidate”;
    }

    Thanks, best regards (And forgive my English 🙂 )

    Plugin Author petermolnar

    (@cadeyrn)

    I think I figured it out: put the location / block to the end of the whole config.
    Apparently that’s the only difference between my runnig & working live setup compared to the ones you’ve posted.

    Plugin Author petermolnar

    (@cadeyrn)

    Could you please confirm if it’s solved or still stands?

    My location / block is at the end of file, but doesn’t resolve the issue.

    Perhaps you should paste your working config.

    Plugin Author petermolnar

    (@cadeyrn)

    My working config ( actually the real confing contains a lot more but not relevant stuff, this is “only” what’s relevant for wordpress & wp-ffpc )
    The map part is generated with plugin Nginx Helper:

    map $host $network_blog_dir {
    	include /var/www/wp-content/plugins/nginx-helper/map.conf;
    }
    
    upstream memcached {
    	server 127.0.0.1:11211;
    }
    
    upstream php-fpm {
    	server unix:/var/run/php5-fpm.sock;
    }
    
    server {
    	## Port
    	listen 80 default_server;
    	listen [::]:80 default_server ipv6only=on;
    
    	## Domains
    	server_name .domain.com;
    
    	## Root dir
    	root /var/www/;
    
    	## log
    	access_log /var/log/nginx/access.log main;
    	error_log /var/log/nginx/error.log;
    
    	## WordPress network files
    	location ~ ^/files/(.*)$ {
    		try_files /wp-content/blogs.dir/$network_blog_dir/$uri /wp-includes/ms-files.php?file=$1 ;
    		expires 7d;
    		add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    	}
    
    	## static files
    	location ~ \.(css|js)$ {
    		expires 7d;
    		add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    		add_header "Vary" "Accept-Encoding";
    	}
    
    	## PHP5-FPM
    	location ~ (\.php|php5-fpm-status) {
    		include params/fastcgi;
    		fastcgi_pass php-fpm;
    		fastcgi_keep_conn on;
    	}
    
    	## try to get result from memcached
    	location @memcached {
    
    		default_type text/html;
    		set $memcached_key data-$scheme://$host$request_uri;
    		set $memcached_request 1;
    
    		# exceptions
    		# avoid cache serve of POST requests
    		if ($request_method = POST ) {
    			set $memcached_request 0;
    		}
    		# avoid cache serve of wp-admin-like pages, starting with "wp-"
    		if ( $uri ~ "/wp-" ) {
    			set $memcached_request 0;
    		}
    		# avoid comment sync caching
    		if ( $uri ~* "sync_comments" ) {
    			set $memcached_request 0;
    		}
    		# avoid cache for logged in users
    		if ($http_cookie ~* "comment_author_|wordpressuser_|wp-postpass_" ) {
    			set $memcached_request 0;
    		}
    
    		if ( $memcached_request = 1) {
    			memcached_pass memcached;
    			error_page 404 = @rewrites;
    		}
    
    		if ( $memcached_request = 0) {
    			rewrite ^ /index.php$request_uri last;
    		}
    	}
    
    	## rewrite rules
    	location @rewrites {
    		rewrite ^ /index.php$request_uri last;
    	}
    
    	location / {
    		try_files $uri $uri/ @memcached;
    	}
    }

    Also, the contents of my (/etc/nginx/) params/fastcgi file:

    fastcgi_param	QUERY_STRING		$query_string;
    fastcgi_param	REQUEST_METHOD		$request_method;
    fastcgi_param	CONTENT_TYPE		$content_type;
    fastcgi_param	CONTENT_LENGTH		$content_length;
    fastcgi_param	SCRIPT_FILENAME		$document_root$fastcgi_script_name;
    fastcgi_param	SCRIPT_NAME		$fastcgi_script_name;
    # fastcgi_param	SCRIPT_FILENAME		$request_filename;
    # fastcgi_param	SCRIPT_NAME		$fastcgi_script_name;
    
    fastcgi_param	REQUEST_URI		$request_uri;
    fastcgi_param	DOCUMENT_URI		$document_uri;
    fastcgi_param	DOCUMENT_ROOT		$document_root;
    fastcgi_param	SERVER_PROTOCOL		$server_protocol;
    
    fastcgi_param	GATEWAY_INTERFACE	CGI/1.1;
    fastcgi_param	SERVER_SOFTWARE		nginx;
    
    fastcgi_param	REMOTE_ADDR		$remote_addr;
    fastcgi_param	REMOTE_PORT		$remote_port;
    fastcgi_param	SERVER_ADDR		$server_addr;
    fastcgi_param	SERVER_PORT		$server_port;
    fastcgi_param	SERVER_NAME		$server_name;
    
    fastcgi_param	PATH_INFO		$fastcgi_path_info;
    fastcgi_param	PATH_TRANSLATED		$document_root$fastcgi_path_info;
    
    # for https
    fastcgi_param	HTTPS			$https if_not_empty;
    fastcgi_param	SSL_PROTOCOL		$ssl_protocol if_not_empty;
    fastcgi_param	SSL_CIPHER		$ssl_cipher if_not_empty;
    fastcgi_param	SSL_SESSION_ID		$ssl_session_id if_not_empty;
    fastcgi_param	SSL_CLIENT_VERIFY	$ssl_client_verify if_not_empty;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param	REDIRECT_STATUS		200;
    
    fastcgi_index 				index.php;
    fastcgi_connect_timeout			10;
    fastcgi_send_timeout			180;
    fastcgi_read_timeout			180;
    fastcgi_buffer_size			512k;
    fastcgi_buffers				4	256k;
    fastcgi_busy_buffers_size		512k;
    fastcgi_temp_file_write_size		512k;
    fastcgi_intercept_errors		on;
    
    # for php
    fastcgi_split_path_info ^(.+\.php)(/.*)$;

    Please keep in mind that I use a self-compiled, dev line nginx, currently version 1.3.13, so I cannot guarantee everything will work from this config with a stable and not modified version of nginx.

    I too was experiencing 404 errors throughout my WP 3.5.1 multisite blog. FWIW I use the nginx Helper and set up conf files pretty much exactly how you set them up, Peter. I was finally able to get this working by adjusting the nginx.conf file as follows (modified from the example above):

    location @memcached {
    # ...snip....see code from Peter's example above above...
    
          		if ( $memcached_request = 1) {
    			# I added this to help debugging. It means a cache "hit"
    			# (meaning you have bypassed PHP/WP entirely) :
           			add_header X-Cache-Engine "WP-FFPC";
    
    			memcached_pass memcached-servers;
           			error_page 404 = @rewrites;
          		}
    
    		if ( $memcached_request = 0) {
    			# before:
    			# rewrite ^ /index.php$request_uri last;
    			# after:
    			rewrite ^ /index.php last;
    		}
    	}
    
    	## rewrite rules
    	location @rewrites {
    		# before:
    		# rewrite ^ /index.php$request_uri last;
    		# after:
    		rewrite ^ /index.php last;
    	}

    During debugging the configuration (perhaps it’s obvious but I kept forgetting so I’ll mention), first:
    1) purge the cache and
    2) disable the plugin entirely.
    This will keep the cached pages (that live on after the plugin is deactivated) from affecting your results.

    If you recently installed or re-installed the Nginx Helper you may need to also adjust your Settings>Permalinks to remove the index.php.

    I hope this helps. Let me know if you need any other information on my setup.

    Plugin Author petermolnar

    (@cadeyrn)

    I’ve digged through the current docs on WP + nginx and it turned out that during the last few years there was a change in the rewrite rule recommendations.
    Alltogether the current ones says to use index.php?$args instead of the one I used index.php$request_uri.

    So in short, the solution: please replace all mentions of
    index.php$request_uri
    to
    index.php?$args

    This sould solve the problem.

    This has the side effect of interfering with valid query strings within the URL. So the URL:
    http://www.example.com/blog/?sandwich=ham-and-cheese
    …shows up with the $_REQUEST variables:
    array(2) { ["/blog/?sandwich"]=> string(14) "ham-and-cheese" ["sandwich"]=> string(14) "ham-and-cheese" }
    …instead of:
    array(1) { ["sandwich"]=> string(14) "ham-and-cheese" }

    More concerning is that the $_SERVER[‘REQUEST_URI’] has now become ‘http://www.example.com/blog/?sandwich’

    I think I’ve followed your configuration example from earlier in this thread but it’s possible I have something misconfigured. That said, the method I describe (where I don’t include the $request_uri at all in the rewrite) appeared to work without any side effects. Could you explain the reason that you need to include the $request_uri in the configuration at all?

    Plugin Author petermolnar

    (@cadeyrn)

    It was required in earlier days; I’m going to replace the snippet nginx sample with a full one, correcting this bug as well in the next version.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘NGiNX 404's’ is closed to new replies.