• Resolved lightboxgroup

    (@lightboxgroup)


    Hi,

    we’ve enabled Falcon Engine without seeing any real improvement, actually from a benchmark test on the homepage the results were worst when activated:

    – w/Wordfence: 5.386s
    – without/Wordfence: 4.674s

    When installed we’ve followed the instructions provided from Wordfence support that were saying to add the following but always getting an error when trying to restart nginx:

    worker_processes 1;
    events {
    worker_connections 1024;
    }
    http {
    include mime.types;
    default_type application/octet-stream;
    log_format main '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time status $status bytes $body_bytes_sent';
    #Uncomment to debug rewrite rules
    #rewrite_log on;
    server {
    listen 80;
    server_name test1.com;
    access_log logs/test1.access.log main;
    #Uncomment to debug rewrite rules
    #error_log logs/rewrite.log notice;
    root /usr/local/test1;
    index index.php;
    
    # WORDFENCE FALCON ENGINE CODE
    #Match on gzip first because ordering matters.
    location ~ "/site/wp-content/wfcache/.*gzip$" {
    gzip off;
    types {}
    default_type text/html;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Content-Encoding gzip;
    }
    #If the previous matched, the following location won't be executed.
    location ~ /site/wp-content/wfcache/.* {
    add_header Vary "Accept-Encoding, Cookie";
    }
    set $wordfenceCacheOn 1;
    
    #Don't cache form submissions.
    if ($request_method = POST) {
    set $wordfenceCacheOn 0;
    }
    
    #Allow caching of /?123=123 because this is a common DDoS to override caches.
    if ($query_string !~ "^(?:d+=d+)?$") {
    set $wordfenceCacheOn 0;
    }
    
    #Only cache URL's ending in /
    if ($request_uri !~ /$) {
    set $wordfenceCacheOn 0;
    }
    #Don't cache any cookies with this in their names e.g. users who are logged in.
    if ($http_cookie ~* "(comment_author|wp-postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher)") {
    set $wordfenceCacheOn 0;
    }
    set $wordfenceEncoding "";
    #Oh, you want gzipped content?
    if ($http_accept_encoding ~ gzip) {
    set $wordfenceEncoding _gzip;
    }
    set $wordfenceHTTPS "";
    if ($scheme = 'https'){
    #If you want to ENABLE HTTPS caching, comment out the next line.
    set $wordfenceCacheOn 0; #Comment this line out to enable HTTPS caching.
    
    set $wordfenceHTTPS '_https'; #Uncomment this line to enable HTTPS caching.
    }
    #The main purpose of this line is to capture the URL components into variables.
    if ($request_uri !~ "^/*(?<wfone>[^/]*)/*(?<wftwo>[^/]*)/*(?<wfthree>[^/]*)/*(?<wffour>[^/]*)/*(?<wffive>[^/]*)(?<wfsix>.*)$"){
    set $wordfenceCacheOn 0;
    }
    #If the file doesn't exist then don't serve from cache.
    if (!-f "$document_root/site/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}") {
    set $wordfenceCacheOn 0;
    }
    
    if ($wordfenceCacheOn = 1) {
    rewrite .* "/site/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}" last;
    }
    # END Wordfence Rules
    
    location / {
    try_files $uri $uri/ /index.php?$args ;
    }
    location ~ .php$ {
    try_files $uri /index.php;
    include fastcgi_params;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    }
    }

    Then we’ve followed the advice from a forum user and created a wf.conffile inside the conf.d directory adding just the following code and including the file in the nginx.conf file:

    server {
    # WORDFENCE FALCON ENGINE CODE
    #Match on gzip first because ordering matters.
    location ~ "/site/wp-content/wfcache/.*gzip$" {
    gzip off;
    types {}
    default_type text/html;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Content-Encoding gzip;
    }
    #If the previous matched, the following location won't be executed.
    location ~ /site/wp-content/wfcache/.* {
    add_header Vary "Accept-Encoding, Cookie";
    }
    set $wordfenceCacheOn 1;
    
    #Don't cache form submissions.
    if ($request_method = POST) {
    set $wordfenceCacheOn 0;
    }
    
    #Allow caching of /?123=123 because this is a common DDoS to override caches.
    if ($query_string !~ "^(?:d+=d+)?$") {
    set $wordfenceCacheOn 0;
    }
    
    #Only cache URL's ending in /
    if ($request_uri !~ /$) {
    set $wordfenceCacheOn 0;
    }
    #Don't cache any cookies with this in their names e.g. users who are logged in.
    if ($http_cookie ~* "(comment_author|wp-postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher)") {
    set $wordfenceCacheOn 0;
    }
    set $wordfenceEncoding "";
    #Oh, you want gzipped content?
    if ($http_accept_encoding ~ gzip) {
    set $wordfenceEncoding _gzip;
    }
    set $wordfenceHTTPS "";
    if ($scheme = 'https'){
    #If you want to ENABLE HTTPS caching, comment out the next line.
    set $wordfenceCacheOn 0; #Comment this line out to enable HTTPS caching.
    
    set $wordfenceHTTPS '_https'; #Uncomment this line to enable HTTPS caching.
    }
    #The main purpose of this line is to capture the URL components into variables.
    if ($request_uri !~ "^/*(?<wfone>[^/]*)/*(?<wftwo>[^/]*)/*(?<wfthree>[^/]*)/*(?<wffour>[^/]*)/*(?<wffive>[^/]*)(?<wfsix>.*)$"){
    set $wordfenceCacheOn 0;
    }
    #If the file doesn't exist then don't serve from cache.
    if (!-f "$document_root/site/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}") {
    set $wordfenceCacheOn 0;
    }
    
    if ($wordfenceCacheOn = 1) {
    rewrite .* "/site/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}" last;
    }
    # END Wordfence Rules
    }

    We then had no problem in restarting the service and managed to activate Falcon Engine. However we didn’t notice any improvement and when trying to load the server through loader.io the test failed after 15 with settings of just 100 connections in 1 minute. Is there a bad configuration? Thanks in advance

    https://ww.wp.xz.cn/plugins/wordfence/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author WFMattR

    (@wfmattr)

    Hi,

    Do you have a link to the other forum user’s post that you mentioned, where they recommended separating the Wordfence code? It should work either way, but may depend on where you place the statements (or the include) in the existing config file.

    Just to make sure — in the first example, you had changed “server_name test1.com;” to your domain, right? (This wouldn’t have caused errors, but may have prevented the settings from ever being used.)

    Also, do you have multiple domains on your server? Depending on the server_name and the rest of your config, it’s possible that the Wordfence config isn’t running.

    Lastly, does loader.io give any details about the failed test? Depending on your Wordfence options, if the cache wasn’t working, the test may have triggered the rate limiting rules, since each hit would be loading a page. (If that does not help, the nginx error log or PHP’s error logs may provide more details.)

    -Matt R

    Thread Starter lightboxgroup

    (@lightboxgroup)

    Dear Matt,

    thanks for your reply, we actually have two server blocks as you can see (where mysite is our domain of course):

    server {
        listen 80;
        server_name www.developmysite.com developmysite.com www.mysite.com;
        return 301 $scheme://mysite.com$request_uri;
    }
    
    server {
        listen 80;
        server_name mysite.com;
    
        root    /usr/share/nginx/www;
        index   index.php index.html index.htm;
    
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    
      location = /sitemap.xml {
        allow all;
        log_not_found off;
        access_log off;
      }

    We would like Falcon to work on mysite.com and not developmysite.com

    Thanks in advance

    Plugin Author WFMattR

    (@wfmattr)

    Hi,

    Where was it that you added the “include” in the main nginx.conf file?

    Also, in the second config file that is being included, did you adjust the paths to match your site? There are a few places in the config sample where the paths begin with “/site/wp-content/”, so it depends on if your site’s WordPress files are in a subdirectory. (If wp-content is directly accessible as yourdomain.com/wp-content/, then you’ll need to remove the “/site” from the beginning of those lines.)

    If the paths were already adjusted for your site, you can post the main nginx.conf and the second one with the Wordfence code — if I can see both config files together with everything but the domain name, that will help. (Make sure to remove the domain again, or other sensitive information, if any.)

    -Matt R

    Thread Starter lightboxgroup

    (@lightboxgroup)

    Dear Matt,

    our include is at the end of the nginx.conf file in the http block

    include /etc/nginx/conf.d/*.conf;

    Here is our updated version of the wf.conf file:

    server {
    # WORDFENCE FALCON ENGINE CODE
    #Match on gzip first because ordering matters.
    location ~ "/usr/share/nginx/www/wp-content/wfcache/.*gzip$" {
    gzip off;
    types {}
    default_type text/html;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Content-Encoding gzip;
    }
    #If the previous matched, the following location won't be executed.
    location ~ /usr/share/nginx/www/wp-content/wfcache/.* {
    add_header Vary "Accept-Encoding, Cookie";
    }
    set $wordfenceCacheOn 1;
    
    #Don't cache form submissions.
    if ($request_method = POST) {
    set $wordfenceCacheOn 0;
    }
    
    #Allow caching of /?123=123 because this is a common DDoS to override caches.
    if ($query_string !~ "^(?:d+=d+)?$") {
    set $wordfenceCacheOn 0;
    }
    
    #Only cache URL's ending in /
    if ($request_uri !~ /$) {
    set $wordfenceCacheOn 0;
    }
    #Don't cache any cookies with this in their names e.g. users who are logged in.
    if ($http_cookie ~* "(comment_author|wp-postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher)") {
    set $wordfenceCacheOn 0;
    }
    set $wordfenceEncoding "";
    #Oh, you want gzipped content?
    if ($http_accept_encoding ~ gzip) {
    set $wordfenceEncoding _gzip;
    }
    set $wordfenceHTTPS "";
    if ($scheme = 'https'){
    #If you want to ENABLE HTTPS caching, comment out the next line.
    set $wordfenceCacheOn 0; #Comment this line out to enable HTTPS caching.
    
    set $wordfenceHTTPS '_https'; #Uncomment this line to enable HTTPS caching.
    }
    #The main purpose of this line is to capture the URL components into variables.
    if ($request_uri !~ "^/*(?<wfone>[^/]*)/*(?<wftwo>[^/]*)/*(?<wfthree>[^/]*)/*(?<wffour>[^/]*)/*(?<wffive>[^/]*)(?<wfsix>.*)$"){
    set $wordfenceCacheOn 0;
    }
    #If the file doesn't exist then don't serve from cache.
    if (!-f "$document_root/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}") {
    set $wordfenceCacheOn 0;
    }
    
    if ($wordfenceCacheOn = 1) {
    rewrite .* "/wp-content/wfcache/${http_host}_${wfone}/${wftwo}~${wfthree}~${wffour}~${wffive}~${wfsix}_wfcache${wordfenceHTTPS}.html${wordfenceEncoding}" last;
    }
    # END Wordfence Rules
    }

    Could it be that the problems is that we continually create posts and update them so the cache get purged too often? Because we still don’t see any improvement…

    Plugin Author WFMattR

    (@wfmattr)

    Hi,

    It sounds like the position of the “include” should be ok. Check the two “location” lines in wf.config though — those , so if you remove “/usr/share/nginx/www”, that will help make the headers right. It looks like the other paths are correct though.

    If you’re not sure whether pages are being added to the cache, on Wordfence’s “Performance Setup” page, click the “Get cache stats” button to see how many pages are cached.

    When you test by manually viewing pages, make sure to use a different browser (or a “private browsing” window) since logged-in users are excluded from seeing cached pages. You can also run loader.io tests again, and check the “Get cache stats” button.

    Having the cache automatically cleared too often can be a problem on some sites, but usually shouldn’t make external tests like loader.io fail — since the requests are so close together, most of them should see cached content, even if the first couple don’t.

    There is a chance that you have a plugin that disables caching when it produces content on a page — that is most common with e-commerce plugins that show cart contents for each user, especially if the cart appears on every page. If you can’t see any pages being cached with the “Get cache stats” button, this might be related.

    -Matt R

    Thread Starter lightboxgroup

    (@lightboxgroup)

    Dear Matt,

    here the Cache Stats:

    Total files in cache: 8
    Total directories in cache: 3
    Total data: 333KB
    Largest file: 101KB
    Oldest file in cache created 19 hours ago.
    Newest file in cache created 19 hours ago.

    Considering that our website is made of about 17000 links is this a normal status?

    Thanks again for all your help

    Thread Starter lightboxgroup

    (@lightboxgroup)

    Consider that we publish probably around 50-60 posts each day…does the cache get completely emptied each time?

    Plugin Author WFMattR

    (@wfmattr)

    Yes, that could definitely be contributing — the cache currently is cleared when any post is published to make sure that the home page and widgets showing posts will all be updated.

    With that fast of a schedule of new posts, the current version Falcon caching might not be best for your site — we are looking at making more options to retain more cached pages based on your choices, but I’m not sure how soon that may be implemented.

    -Matt R

    Thread Starter lightboxgroup

    (@lightboxgroup)

    Ok great! In the meantime thanks for all your support Matt!

    (If wp-content is directly accessible as yourdomain.com/wp-content/, then you’ll need to remove the “/site” from the beginning of those lines.)

    Thank you Matt! This fixed it for me. Might be a good idea to point this out on the WordFence NGINX config instructions, for other noob/lazy people like me 🙂 I’m guessing most WP sites nowadays have it installed in the root.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Nginx Conf’ is closed to new replies.