8

Enhance nginx (user) template support


Avatar
Hosted Power

Too bad that there is a sophisticated system for nginx templates but it's too limited for certain use cases.

It would be nice if the nginx user template could also be used "globally" for a site instead of on location / (or another location) inside the nginx config.

For example this is now what happens inside the user/nginx.conf:

# use fastcgi for all php files

location ~ .php$
{
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE if_not_empty;
fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE if_not_empty;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if ( $skip_cache ~ "^$" ) {
set $skip_cache 1;
}
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache FASTCGICACHE;
fastcgi_cache_valid 60m;
include /etc/nginx/nginx_limits.conf;
if (-f $request_filename)
{
fastcgi_pass unix:/usr/local/php73/sockets/hefranl.sock;
}
}
include /etc/nginx/webapps.conf;
location ~ "^()(/.*)?$"
{
set $template_location "$1/";
set $relative_location "$2";
include /etc/nginx/templates/hostedpower_magento2.conf;
# use fastcgi for all php files




Add an extra "special location" global, which would generate this config:

include /etc/nginx/templates/hostedpower_magento2.conf;
# use fastcgi for all php files
location ~ .php$
{
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE if_not_empty;
fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE if_not_empty;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if ( $skip_cache ~ "^$" ) {
set $skip_cache 1;
}
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache FASTCGICACHE;
fastcgi_cache_valid 60m;
include /etc/nginx/nginx_limits.conf;
if (-f $request_filename)
{
fastcgi_pass unix:/usr/local/php73/sockets/hefranl.sock;
}
}
include /etc/nginx/webapps.conf;




By injecting the template into a certain location, one runs into a lot of nginx limitations as we found out now.

For example we cannot even set (global) variables, since the extra locations are not handled by our php handler, but they are handled by the "global" handler of which we have no control in the template.

I think a pretty simple solution could be that we can specify a location "global" (or similar) of our template.

e.g. / /wp (already possible) and then also location "global". Which would be inserted into the server{} config instead of under a location.

A

Activity Newest / Oldest

Avatar

Hosted Power

Also charset configuration is not reliable and not active on all requests:

nginx.org/en/docs/http/ngx_http_charset_module.html

e.g. charset UTF-8;
The problem wouldn't exist if we could set charset outside the location directive


Avatar

Hosted Power

Also charset configuration is not reliable and not active on all requests:

nginx.org/en/docs/http/ngx_http_charset_module.html

e.g. charset UTF-8;
The problem wouldn't exist if we could set charset outside the location directive


Avatar

Hosted Power

removed