Hello @alexliii
Thank you for reaching out and I am happy to assist you with this.
To confirm, have you restarted the Nginx as suggested by the W3TC notification?
In performance>Install, you can find all the rewrite rules (depending on the configuration), there you can also see the path to the nginx.conf file that W3TC should be using for those rewrite rules.
It would be best if you could share the website URL and let me know which settings are enabled in the W3 Total Cache, like Page Cache, and which settings are in the Browser Cache so we can check if the W3TC is adding necessary headers.
Alternatively, you can copy and paste the rewrite rules in Performance>Install to the nginx. conf in the path as suggested by the W3TC Install page.
Thanks!
Hello,
Here is the content under Performance>Install:
Rewrite Rules (based on active settings)
/var/www/lovcour.com/htdocs/nginx.conf:
# BEGIN W3TC Page Cache core
set $w3tc_rewrite 1;
if ($request_method = POST) {
set $w3tc_rewrite 0;
}
if ($query_string != "") {
set $w3tc_rewrite 0;
}
set $w3tc_slash "";
if ($request_uri ~ \/$) {
set $w3tc_slash _slash;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
set $w3tc_rewrite 0;
}
set $w3tc_preview "";
if ($http_cookie ~* "(w3tc_preview)") {
set $w3tc_preview _preview;
}
set $w3tc_ssl "";
if ($scheme = https) {
set $w3tc_ssl _ssl;
}
if ($http_x_forwarded_proto = 'https') {
set $w3tc_ssl _ssl;
}
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
set $w3tc_enc _gzip;
}
if (!-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_slash$w3tc_ssl$w3tc_preview.html$w3tc_enc") {
set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_slash$w3tc_ssl$w3tc_preview.html$w3tc_enc" last;
}
# END W3TC Page Cache core
# BEGIN W3TC Page Cache cache
location ~ /wp-content/cache/page_enhanced.*gzip$ {
gzip off;
types {}
default_type text/html;
add_header Content-Encoding gzip;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "max-age=3600, public";
add_header Referrer-Policy "no-referrer-when-downgrade";
}
# END W3TC Page Cache cache
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
location ~ \.(css|htc|less|js|js2|js3|js4)$ {
expires 31536000s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header Referrer-Policy "no-referrer-when-downgrade";
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$ {
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "max-age=3600, public";
add_header Referrer-Policy "no-referrer-when-downgrade";
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(asf|asx|wax|wmv|wmx|avi|avif|avifs|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
expires 31536000s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header Referrer-Policy "no-referrer-when-downgrade";
try_files $uri $uri/ /index.php?$args;
}
add_header Referrer-Policy "no-referrer-when-downgrade";
# END W3TC Browser Cache
Upon your suggestion: Alternatively, you can copy and paste the rewrite rules in Performance>Install to the nginx. conf in the path as suggested by the W3TC Install page.
Which one nginx.conf do you mean please here? I can find there is a nginx.conf created by W3 in /var/www/lovcour.com/htdocs, and the rules already there, and here is screenshot at https://prnt.sc/jtCnx16jkSsM
Or, do you mean I should include those rules to some nginx.conf, and please note here is structure of our Nginx configuration:
/etc/nginx/sites-available/site.tld
server {
# Uncomment the following line for domain mapping
# listen 80 default_server;
server_name mysite.com *.mysite.com;
# Uncomment the following line for domain mapping
#server_name_in_redirect off;
access_log /var/log/nginx/mysite.com.access.log rt_cache;
error_log /var/log/nginx/mysite.com.error.log;
root /var/www/mysite.com/htdocs;
index index.php index.html index.htm;
include common/wpfc-php81.conf;
include common/wpsubdir.conf;
include common/wpcommon-php81.conf;
include common/locations-wo.conf;
include /var/www/mysite.com/conf/nginx/*.conf;
}
Looking forward to your reply.
-
This reply was modified 3 years, 4 months ago by
alexliii.
By the way, Nginx fastcgi cache is enabled now.
Should I rename the nginx.conf( in /var/www/lovcour.com/htdocs/nginx.conf) to be Nginx_W3.conf
Then, include it into the directory at /etc/nginx/sites-available/site.tld ?
Then, it will be look like this way:
/etc/nginx/sites-available/site.tld
server {
# Uncomment the following line for domain mapping
# listen 80 default_server;
server_name mysite.com *.mysite.com;
# Uncomment the following line for domain mapping
#server_name_in_redirect off;
access_log /var/log/nginx/mysite.com.access.log rt_cache;
error_log /var/log/nginx/mysite.com.error.log;
root /var/www/mysite.com/htdocs;
index index.php index.html index.htm;
include common/wpfc-php81.conf;
include common/wpsubdir.conf;
include common/wpcommon-php81.conf;
include common/locations-wo.conf;
include /var/www/mysite.com/conf/nginx/*.conf;
include common/Nginx_W3.conf
}
-
This reply was modified 3 years, 4 months ago by
alexliii.
Hello @alexliii
Well, this means that the W3TC rules are where they need to be and everything is working as expected. The W3TC uses the nginx. conf in the root of your website and as you suggested, all the rules (according to the configuration) are there.
You should not rename that file because this is the Nginx configuration file!
Thanks!
Sorry, I am confused, how does Nginx use that ngnix.conf(/var/www/lovcour.com/htdocs/nginx.conf)created by W3?
I did not find where it was included in our Nginx configuration (/etc/nginx/sites-available/site.tld )
Also, I did not find any info of W3 cache in the header, did you checked our website?
Hello @vmarko,
I did not find Nginx.conf by W3 was included in sites-available/site.tld , would you please clarify how it works with Ngin?
Thanks
Hello @alexliii
The WordPress is installed in the /htdocs/ The nginx.conf file there is handling the rules for your website as you have seen in the screenshot you shared.
As you can see, there are rules for page caching (because you are using Disk Enhanced) and Browser Cache.
When inspecting the source and check the files on your website I can see the headers:
- cache-control: max-age=3600, public
- content-encoding: gzip
- date: Wed, 18 Jan 2023 12:27:01 GMT
- etag: “b070a9e9e25f398a182fce9a086e7bb9”
- last-modified: Wed, 18 Jan 2023 12:27:01 GMT
This means that the options enabled in Browser Cache like Cache-control, gzip, etag, etc are set.
So the only ngix.conf W3 Total Cache can use is the one mentioned above, the other nginx configuration files cannot be modified by the W3 Total Cache.
This is a normal behavior.
Thanks!