nginx fast cache not working

knoll

Verified User
Joined
Sep 26, 2005
Messages
140
Location
Belgium
hey,

first i installed nginx as webserver and with php7
it runs and site is working but not fast yet.

then i tryed fastcgi cache i followed some guides online trying to make something for directadmin use.
since directadmin doesn't have a working howto (not that i find)
i tryed to test fastcgi cache with curl and a time script that should be cached from the manual i saw.

from the manual it should be all the same number so it doesn't work:
[root@test ~]# curl http://www.aloeverawinkel.be/time.php;echo
1542721024
[root@test ~]# curl http://www.aloeverawinkel.be/time.php;echo
1542721027
[root@test ~]# curl http://www.aloeverawinkel.be/time.php;echo
1542721030
[root@test ~]#


in the logs nothing that helps me i'm caching in /var/nginx/cache
directory created and with permission correct i guess:
[root@test ~]# ls -l /var
total 80
drwxr-xr-x 3 nginx nginx 4096 Nov 19 20:19 nginx

[root@test ~]# ls -l /var/nginx
total 4
drwxr-xr-x 2 nginx nginx 4096 Nov 19 20:19 cache
[root@test ~]#

so i guess its correct since nginx is running under nginx:

in directadmin.conf i have this related to nginx:
nginx=1
nginx_proxy=0

-------------------------------------

options.conf:
#PHP Settings
php1_release=7.2
php1_mode=php-fpm
php2_release=no
php2_mode=php-fpm
secure_php=no
opcache=no
htscanner=no
php_ini=no
php_timezone=Europe/London
php_ini_type=production
ioncube=no
zend=no
suhosin=no
x_mail_header=yes
#WEB Server Settings
webserver=nginx
http_methods=GET:HEAD:POST
litespeed_serialno=trial
modsecurity=no
modsecurity_ruleset=comodo
apache_ver=2.4
apache_mpm=auto
mod_ruid2=no
userdir_access=yes
harden_symlinks_patch=yes
use_hostname_for_alias=no
redirect_host=myserverhost
redirect_host_https=no
#CustomBuild Settings
custombuild=2.0
autover=no
bold=yes
clean=yes
cleanapache=yes
clean_old_tarballs=yes
clean_old_webapps=yes
downloadserver=files6.directadmin.com


------------------------------------------------

than the configs nginx.conf in /etc/nginx:

#user nginx;

worker_processes 3;
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/directadmin-ips.conf;
include /etc/nginx/directadmin-settings.conf;
include /etc/nginx/nginx-vhosts.conf;
include /etc/nginx/directadmin-vhosts.conf;
}

----------------------------------------------------------------------------

than config /usr/local/directadmin/data/users/myuser/nginx.conf :

fastcgi_cache_path /var/nginx/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

# Auto generated nginx config file by DirectAdmin version 1.54.1
# Modifying this file is not recommended as any changes you make will be
# overwritten when the user makes any changes to their website

# For global config changes that affect all Users, see this guide:
# http://help.directadmin.com/item.php?id=558
# For local config changes that only affect one User, see this guide:
# http://help.directadmin.com/item.php?id=3


server
{
listen 185.83.218.116:80;
server_name aloeverawinkel.be www.aloeverawinkel.be ;
access_log /var/log/nginx/domains/aloeverawinkel.be.log;
access_log /var/log/nginx/domains/aloeverawinkel.be.bytes bytes;
error_log /var/log/nginx/domains/aloeverawinkel.be.error.log;
root /home/aloevera/domains/aloeverawinkel.be/public_html;
index index.php index.html index.htm;
include /usr/local/directadmin/data/users/aloevera/nginx_php.conf;
include /etc/nginx/webapps.conf;

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/|index.php|sitemap(_index)?.xml") {
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;
}

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


location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/usr/local/php72/sockets/aloevera.sock;

fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;

fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}

location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}

location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
}


server {
listen 185.83.218.116:443 ssl http2;
server_name aloeverawinkel.be www.aloeverawinkel.be ;
access_log /var/log/nginx/domains/aloeverawinkel.be.log;
access_log /var/log/nginx/domains/aloeverawinkel.be.bytes bytes;
error_log /var/log/nginx/domains/aloeverawinkel.be.error.log;
root /home/aloevera/domains/aloeverawinkel.be/private_html;
index index.php index.html index.htm;
ssl_certificate /usr/local/directadmin/data/users/aloevera/domains/aloeverawinkel.be.cert.combined;
ssl_certificate_key /usr/local/directadmin/data/users/aloevera/domains/aloeverawinkel.be.key;
include /usr/local/directadmin/data/users/aloevera/nginx_php.conf;
include /etc/nginx/webapps.ssl.conf;
try_files $uri $uri/ /index.php?$uri&$args;
}

------------------------------------------------------ end of config.


when i try to get headers with curl i get this:

[root@test aloevera]# curl -X GET -I http://www.aloeverawinkel.be/
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 20 Nov 2018 13:44:08 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/7.2.12
X-Pingback: http://www.aloeverawinkel.be/xmlrpc.php
Link: <http://www.aloeverawinkel.be/wp-json/>; rel="https://api.w.org/"
Link: <http://www.aloeverawinkel.be/>; rel=shortlink

[root@test aloevera]#

all times the same

i really don't know what to do i tryed nginx_apache first that was a mess to due of lack of good manuals here for people that don't work all day with it ;)

and now i try pure nginx with php and still the same not working...

i hope someone can give me something that it could work with or even if you don't trust here to put an good example pm is allowed with config where to do what?

i allready tryed +40 hours changing and changing to get this working (together with the tryes of nginx-apache)

I really hope someone wants to give me the correct ways how to do it and wants to put an infort to help me for someone with the knowledge its only a fraction of the time for a newbie to find out it, and we all started somewhere.

i know i could do google pageload module etc to help it faster but i want to try fastcgi first this is my problem that i can't get it working.

Greets,
Alex
 
and i know editing and make changes to /usr/local/directadmin/data/users/ is gone but its the fastest way to test and tryout if you don't want to lose time with rebuild configs etc.
if i know how i can still edit the right configs and set it all ok :)
 
Hello Alex,

For NGINX+Apache you need to use proxy cache directives in NGINX and enable nginx proxy buffering in directadmin.conf. Check it here: https://help.poralix.com/articles/nginx-does-not-cache-data-on-directadmin-server


As for now though I get the headers: no-cache


Code:
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Date: Mon, 26 Nov 2018 16:54:14 GMT
X-Page-Speed: Powered By ngx_pagespeed
Cache-Control: max-age=0, no-cache

content seems still to be cached:

Code:
1543251231

i.e. 11/26/2018 @ 4:53pm (UTC) and the current time is 4:58pm (UTC)
 
Back
Top