Hey,
i'm 3 days trying to get nginx cache working
i installed nginx_apache
apache is caching with opcache
but nginx cache isn't working
[root@gsi2 ~]# curl --head http://www.mydomain/
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 23 Oct 2018 09:56:23 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/7.2.11
Link: <http://www.mydomain/wp-json/>; rel="https://api.w.org/"
Cache-Control: max-age=0, no-cache
Vary: Accept-Encoding,User-Agent
i tryed almost every howto online not working
i want this because i want later to change to https but than the site drops speed by 300%
[root@gsi2 ~]# cat /usr/local/directadmin/conf/directadmin.conf |grep nginx_proxy_buffering
nginx_proxy_buffering=1
this is my nginx.conf:
#user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
events {
include /etc/nginx/nginx-events.conf;
}
http {
include /etc/nginx/mime.types;
# For user configurations not maintained by DirectAdmin. Empty by default.
include /etc/nginx/nginx-includes.conf;
# Supplemental configuration
include /etc/nginx/nginx-modsecurity-enable.conf;
include /etc/nginx/nginx-defaults.conf;
include /etc/nginx/nginx-gzip.conf;
include /etc/nginx/nginx-proxy.conf;
include /etc/nginx/directadmin-ips.conf;
include /etc/nginx/directadmin-settings.conf;
include /etc/nginx/nginx-vhosts.conf;
include /etc/nginx/directadmin-vhosts.conf;
include /etc/nginx/sites-enabled/*;
fastcgi_cache_path /var/cache/nginx2 levels=1:2 keys_zone=microcache:5m max_size=1000m;
log_format cache '$remote_addr - $remote_user [$time_local] "$request" '
'$status $upstream_cache_status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Enable session tickets
ssl_session_tickets on;
}
------------------
nginx-proxy.conf:
[root@gsi2 nginx]# cat nginx-proxy.conf
proxy_connect_timeout 150s;
proxy_send_timeout 150s;
proxy_read_timeout 1800s;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 10m;
-----------------------------
i added sites-available and sites-enabled (dirs not created by DA)
this is mydomein.tld.conf in directory sites-available and sites-enabled symlinked to there:
#
# your website
#
server {
listen 80;
server_name mydomain.tld www.mydomain.tld;
access_log off;
error_log /var/log/httpd/mydomain.tld-error_log;
root /home/historics/public_html/;
location / {
index index.php index.html index.htm;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
location ~ \.php$ {
# Setup var defaults
set $no_cache "";
# If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
if ($request_method !~ ^(GET|HEAD)$) {
set $no_cache "1";
}
# Drop no cache cookie if need be
# (for some reason, add_header fails if included in prior if-block)
if ($no_cache = "1") {
add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
add_header X-Microcachable "0";
}
# Bypass cache if no-cache cookie is set
if ($http_cookie ~* "_mcnc") {
set $no_cache "1";
}
# Bypass cache if flag is set
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
fastcgi_cache microcache;
fastcgi_cache_key $server_name|$request_uri;
fastcgi_cache_valid 404 30m;
fastcgi_cache_valid 200 10s;
fastcgi_max_temp_file_size 1M;
fastcgi_cache_use_stale updating;
fastcgi_pass localhost:9000;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
#fastcgi_intercept_errors on;
include fastcgi_params;
}
}
----------------------------------------------------
i even tryed this guide:
https://guides.wp-bullet.com/how-to-configure-nginx-reverse-proxy-wordpress-cache-apache/
with this reverse thing in sites-enabled:
# WP Bullet nginx proxy cache
# Author Mike from https://guides.wp-bullet.com
#fix 504 gateway timeouts, can go in nginx.conf
send_timeout 600;
#set the location of the cached files, zone, name, size (1000 MB) and how long to cache for 600 minutes
proxy_cache_path /var/run/proxy_cache levels=1:2 keys_zone=WORDPRESS-PROXY:10m max_size=1000m inactive=600m use_temp_path=off;
#prevent header too large errors
#httpoxy exploit protection
proxy_set_header Proxy "";
# add forwarded for header
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server {
listen 80 default;
access_log /var/log/nginx/proxy-access.log;
error_log /var/log/nginx/proxy-error.log;
# show cache status and any skip cache reason
add_header WP-Bullet-Proxy-Cache $upstream_cache_status;
add_header Cache-BYPASS-Reason $skip_reason;
# define nginx variables
set $do_not_cache 0;
set $skip_reason "";
set $bypass 0;
# security for bypass so localhost can empty cache
if ($remote_addr ~ "^(127.0.0.1|185.244.39.54)$") {
set $bypass $http_secret_header;
}
# skip caching WordPress cookies
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
set $skip_reason Cookie;
}
# Don't cache URIs containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|sitemap(_index)?.xml") {
set $skip_cache 1;
set $skip_reason URI;
}
location / {
proxy_set_header Host $host;
# may need to comment out proxy_redirect if get login redirect loop
proxy_redirect off;
proxy_cache WORDPRESS-PROXY;
proxy_cache_revalidate on;
proxy_ignore_headers Expires Cache-Control;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_bypass $bypass $do_not_cache;
proxy_no_cache $do_not_cache;
proxy_cache_valid 200 301 302 500m;
proxy_cache_valid 404 1m;
#can rename PURGE to whatever you want, should restrict it to backend server requests for security
# pass requests onto your PHP backend
proxy_pass http://127.0.0.1:8080;
}
# allows purging via special URL
location ~ /purge(/.*) {
allow 127.0.0.1;
allow 185.244.39.54;
deny all;
}
}
------------- (btw i had to remove a few duplicated things to get nginx worked) ------
but nginx cache is not working...
I hope someone can help me i don't want to try 7days 5 hours a day
many thanks on advance !!!!
greets alex
i'm 3 days trying to get nginx cache working
i installed nginx_apache
apache is caching with opcache
but nginx cache isn't working
[root@gsi2 ~]# curl --head http://www.mydomain/
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 23 Oct 2018 09:56:23 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/7.2.11
Link: <http://www.mydomain/wp-json/>; rel="https://api.w.org/"
Cache-Control: max-age=0, no-cache
Vary: Accept-Encoding,User-Agent
i tryed almost every howto online not working
i want this because i want later to change to https but than the site drops speed by 300%
[root@gsi2 ~]# cat /usr/local/directadmin/conf/directadmin.conf |grep nginx_proxy_buffering
nginx_proxy_buffering=1
this is my nginx.conf:
#user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
events {
include /etc/nginx/nginx-events.conf;
}
http {
include /etc/nginx/mime.types;
# For user configurations not maintained by DirectAdmin. Empty by default.
include /etc/nginx/nginx-includes.conf;
# Supplemental configuration
include /etc/nginx/nginx-modsecurity-enable.conf;
include /etc/nginx/nginx-defaults.conf;
include /etc/nginx/nginx-gzip.conf;
include /etc/nginx/nginx-proxy.conf;
include /etc/nginx/directadmin-ips.conf;
include /etc/nginx/directadmin-settings.conf;
include /etc/nginx/nginx-vhosts.conf;
include /etc/nginx/directadmin-vhosts.conf;
include /etc/nginx/sites-enabled/*;
fastcgi_cache_path /var/cache/nginx2 levels=1:2 keys_zone=microcache:5m max_size=1000m;
log_format cache '$remote_addr - $remote_user [$time_local] "$request" '
'$status $upstream_cache_status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Enable session tickets
ssl_session_tickets on;
}
------------------
nginx-proxy.conf:
[root@gsi2 nginx]# cat nginx-proxy.conf
proxy_connect_timeout 150s;
proxy_send_timeout 150s;
proxy_read_timeout 1800s;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 10m;
-----------------------------
i added sites-available and sites-enabled (dirs not created by DA)
this is mydomein.tld.conf in directory sites-available and sites-enabled symlinked to there:
#
# your website
#
server {
listen 80;
server_name mydomain.tld www.mydomain.tld;
access_log off;
error_log /var/log/httpd/mydomain.tld-error_log;
root /home/historics/public_html/;
location / {
index index.php index.html index.htm;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
location ~ \.php$ {
# Setup var defaults
set $no_cache "";
# If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
if ($request_method !~ ^(GET|HEAD)$) {
set $no_cache "1";
}
# Drop no cache cookie if need be
# (for some reason, add_header fails if included in prior if-block)
if ($no_cache = "1") {
add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
add_header X-Microcachable "0";
}
# Bypass cache if no-cache cookie is set
if ($http_cookie ~* "_mcnc") {
set $no_cache "1";
}
# Bypass cache if flag is set
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
fastcgi_cache microcache;
fastcgi_cache_key $server_name|$request_uri;
fastcgi_cache_valid 404 30m;
fastcgi_cache_valid 200 10s;
fastcgi_max_temp_file_size 1M;
fastcgi_cache_use_stale updating;
fastcgi_pass localhost:9000;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
#fastcgi_intercept_errors on;
include fastcgi_params;
}
}
----------------------------------------------------
i even tryed this guide:
https://guides.wp-bullet.com/how-to-configure-nginx-reverse-proxy-wordpress-cache-apache/
with this reverse thing in sites-enabled:
# WP Bullet nginx proxy cache
# Author Mike from https://guides.wp-bullet.com
#fix 504 gateway timeouts, can go in nginx.conf
send_timeout 600;
#set the location of the cached files, zone, name, size (1000 MB) and how long to cache for 600 minutes
proxy_cache_path /var/run/proxy_cache levels=1:2 keys_zone=WORDPRESS-PROXY:10m max_size=1000m inactive=600m use_temp_path=off;
#prevent header too large errors
#httpoxy exploit protection
proxy_set_header Proxy "";
# add forwarded for header
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server {
listen 80 default;
access_log /var/log/nginx/proxy-access.log;
error_log /var/log/nginx/proxy-error.log;
# show cache status and any skip cache reason
add_header WP-Bullet-Proxy-Cache $upstream_cache_status;
add_header Cache-BYPASS-Reason $skip_reason;
# define nginx variables
set $do_not_cache 0;
set $skip_reason "";
set $bypass 0;
# security for bypass so localhost can empty cache
if ($remote_addr ~ "^(127.0.0.1|185.244.39.54)$") {
set $bypass $http_secret_header;
}
# skip caching WordPress cookies
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
set $skip_reason Cookie;
}
# Don't cache URIs containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|sitemap(_index)?.xml") {
set $skip_cache 1;
set $skip_reason URI;
}
location / {
proxy_set_header Host $host;
# may need to comment out proxy_redirect if get login redirect loop
proxy_redirect off;
proxy_cache WORDPRESS-PROXY;
proxy_cache_revalidate on;
proxy_ignore_headers Expires Cache-Control;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_bypass $bypass $do_not_cache;
proxy_no_cache $do_not_cache;
proxy_cache_valid 200 301 302 500m;
proxy_cache_valid 404 1m;
#can rename PURGE to whatever you want, should restrict it to backend server requests for security
# pass requests onto your PHP backend
proxy_pass http://127.0.0.1:8080;
}
# allows purging via special URL
location ~ /purge(/.*) {
allow 127.0.0.1;
allow 185.244.39.54;
deny all;
}
}
------------- (btw i had to remove a few duplicated things to get nginx worked) ------
but nginx cache is not working...
I hope someone can help me i don't want to try 7days 5 hours a day
many thanks on advance !!!!
greets alex