Welcome! Log In Create A New Profile

Advanced

avoid repeating the same set of directive in every location

Posted by sevy 
avoid repeating the same set of directive in every location
September 20, 2013 01:57PM
Hello everybody.
I've been searching the forum and google for this but didn't find any tutorial or wiki page.

I have some server setup which needs some specific directives for each location and them always the same directives repeated for every loation.
Example:

server {
listen 11.22.33.44:80;
server_name example.com www.example.com;

location ~ ^/index\.php? {
root /path/to/root;
expires 600s;
add_header Cache-Control public;
add_header Cahe-Status $upstream_cache_status;
fastcgi_cache_min_uses 0;
fastcgi_cache_valid 200 600s;
fastcgi_cache_use_stale off;
fastcgi_cache WEBCACHE;
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_ignore_client_abort on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/root$fastcgi_script_name;
fastcgi_buffer_size 32k;
fastcgi_buffers 256 16k;
include fastcgi_params;
error_page 404 /404.html;
}

location ~ ^/static_page\.php {
root /path/to/root;
expires 1d;
add_header Cache-Control public;
add_header Cahe-Status $upstream_cache_status;
fastcgi_cache_min_uses 0;
fastcgi_cache_valid 200 1d;
fastcgi_cache_use_stale off;
fastcgi_cache WEBCACHE;
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_ignore_client_abort on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/root$fastcgi_script_name;
fastcgi_buffer_size 32k;
fastcgi_buffers 256 16k;
include fastcgi_params;
error_page 404 /404.html;
}

location ~ ^/dynamic_page\.php {
root /path/to/root;
fastcgi_ignore_client_abort on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/root$fastcgi_script_name;
fastcgi_buffer_size 32k;
fastcgi_buffers 256 16k;
include fastcgi_params;
error_page 404 /404.html;
}
and so on...

My goal would be to create a set of directives that are always the same in every specific location, so I don't have to change a single directive in each and every location, once I need to switch something.

An example would be that on every location i'd need the following parameters to be always the same for every location:
fastcgi_cache_min_uses 0;
fastcgi_cache_use_stale off;
fastcgi_ignore_client_abort on;

The problem is that I cannot define all the "repeated directives" into the server section since I serve alot of other stuff directly from the root, and there are specific cases where I could not need some of them. Due to my system architecture I must have every php page set with it's own location, but when it comes to change some parameter such as fastcgi_cache_use_stale it becomes a pain in the ass because I have to change it on more than 200 locations.

The only fix for this that comes to my mind is to use an include in every location to an external file such as

include /path/to/repeated_directives.conf

into every location. But I was loking for a more elegant way to do this. Also because I have the same architecture on several virtual hosts so i'd probably have to setup a new repeated_directives-hostname.conf for each virtual host and this would mean to edit an external file every time, while having the setup into the server location would be faster.

Any help is greatfully appreciated.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 84
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready