I want to take full advantage of FastCGI Cache and use a plugin to purge it from time to time. I know that you can place the fastcgi_cache_path above the server directive, but is it possible to make the path dynamic based on the loaded vhost by placing something like this fastcgi_cache_path $document_root./cache/ levels=1:2 keys_zone=fideloper:100m inactive=60m; at the top of a custom nginx master host file? If not, is there some other possible way to accomplish this to allow each vhost to have it's own specified cache path?
You can modify and customize the /usr/local/ispconfig/server/conf/nginx_vhost.conf.master file which is used to create the vhost files. you can find a lot of placeholders inside like the document root or domain name variable that you can use within the path. Just ensure that you save the modified copy of the file to /usr/local/ispconfig/server/conf-custom/ folder so it does not get overwritten on updates.
So, I turned on debugging just in case, edited my /usr/local/ispconfig/server/conf-custom/nginx_vhost.conf.master file, and added the following before the server directive: Code: fastcgi_cache_path <tmpl_var name='document_root'>/cache/ levels=1:2 keys_zone=microcache:10m 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"'; fastcgi_cache_key "$scheme$request_method$host$request_uri"; However, it created vhost.err files. In the ispconfig.log, there are two warnings: nginx did not restart after the configuration change for website .... Reason for nginx restart failure: Job for nginx.service failed. See "systemctl status nginx.service" and "journalctl -xe" for details. Then I ran the following command: systemctl status nginx.service Code: nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2015-08-18 07:50:44 EDT; 1min 4s ago Process: 18559 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS) Process: 17528 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS) Process: 18610 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 18607 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 18611 (nginx) CGroup: /system.slice/nginx.service ├─18611 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─18612 nginx: worker process ├─18613 nginx: worker process ├─18614 nginx: worker process ├─18615 nginx: worker process └─18616 nginx: cache manager process Aug 18 07:50:44 reformed.edutrac.org systemd[1]: Starting A high performance web server and a reverse proxy server... Aug 18 07:50:44 reformed.edutrac.org systemd[1]: Started A high performance web server and a reverse proxy server. I can't immediately see where the issue is. Did I not do it right?
When nginx fails to start, then ispconfig creates a vhost file with .err ending and uses the last working config again. Check out the genereted .err file if the configuration is correct and that e.g. paths that you use really exist and are writable by the nginx user. Then you can rename the current vhost file to e.g. vhost.bak and the vhost.err file to .vhost and then restart nginx to see the errors in the log and on the shell.
Ugh! I can't get it to work. First keys_zone needed to be unique, so I changed it to keys_zone=<tmpl_var name='domain'>. Then log_format needed to be unique, so I changed it to log_format <tmpl_var name='domain'>.cache. Lastly, fastcgi_cache_key seems it also needs to be unique, but I thought it would be unique and that's the format I need for every site. So, I am lost.
Are you sure that the user "nginx" is able to write to the folder fastcgi_cache_path <tmpl_var name='document_root'>/cache/ ? Maybe you better use a path outside of the web root like /var/cache/nginx/<tmpl_var name='domain'> and ensure that this folder exists and is writable by the user "nginx".
That is why I am trying to create it for each vhost under it's document root. The plugin I am using on each site cannot purge /var/cache/nginx because it doesn't have access to it. If there is a better solution than what I am trying to do, I welcome it.