Skip to content

Commit

Permalink
cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Dec 13, 2023
1 parent ae0678f commit e028895
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 26 deletions.
31 changes: 18 additions & 13 deletions app/Recipes/Laravel/LaravelRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,35 @@ private function build_nginx(Php $php): Nginx
$nginx->set_volume($custom_certificates_folder, '/etc/letsencrypt');
}


$nginx->add_site($this->host(), 80, '/var/www/public', null, null, '
$extra_site_config = "
location /socket.io {
proxy_pass http://localhost:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"Upgrade\";
}
";

if(($cache_age = env('NGINX_CACHE_AGE')) && ($cache_files = env('NGINX_CACHE_FILES'))){
$extra_site_config .= "
location ~* \.($cache_files)$ {
expires $cache_age;
etag off;
if_modified_since off;
add_header Cache-Control \"public, no-transform\";
}
');
";
}

$nginx->add_site($this->host(), 80, '/var/www/public', null, null, $extra_site_config);

if (env('NGINX_CUSTOM_CERTIFICATES_HOSTNAME')) {
$certificate_hostname = env('NGINX_CUSTOM_CERTIFICATES_HOSTNAME', $this->host());
$ssl_certificate = "/etc/letsencrypt/live/$certificate_hostname/fullchain.pem";
$ssl_certificate_key = "/etc/letsencrypt/live/$certificate_hostname/privkey.pem";
}

$nginx->add_site($this->host(), 443, '/var/www/public', $ssl_certificate ?? null, $ssl_certificate_key ?? null, '
location /socket.io {
proxy_pass http://localhost:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
');
$nginx->add_site($this->host(), 443, '/var/www/public', $ssl_certificate ?? null, $ssl_certificate_key ?? null, $extra_site_config);


if (!empty(env('NGINX_PORT'))) {
Expand Down
34 changes: 22 additions & 12 deletions app/Recipes/PlainPhp/PlainPhpRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,34 @@ private function build_nginx(): Nginx{

$nginx_root = env('NGINX_ROOT', '/var/www');

$extra_site_config = "
location /socket.io {
proxy_pass http://localhost:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"Upgrade\";
}
";

if(($cache_age = env('NGINX_CACHE_AGE')) && ($cache_files = env('NGINX_CACHE_FILES'))){
$extra_site_config .= "
location ~* \.($cache_files)$ {
expires $cache_age;
etag off;
if_modified_since off;
add_header Cache-Control \"public, no-transform\";
}
";
}


$nginx->add_site(
$this->host(),
80,
$nginx_root,
null,
null,
'location /socket.io {
proxy_pass http://localhost:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}');
$extra_site_config);

if(env('NGINX_CUSTOM_CERTIFICATES_HOSTNAME')){
$certificate_hostname = env('NGINX_CUSTOM_CERTIFICATES_HOSTNAME', $this->host());
Expand All @@ -256,12 +271,7 @@ private function build_nginx(): Nginx{
$nginx_root,
$ssl_certificate ?? null,
$ssl_certificate_key ?? null,
'location /socket.io {
proxy_pass http://localhost:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}');
$extra_site_config);


if(!empty(env('NGINX_PORT'))){
Expand Down
3 changes: 3 additions & 0 deletions storage/app/env/Laravel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ NGINX_PORT_SSL=443
#NGINX_CUSTOM_CERTIFICATES_FOLDER=
#NGINX_CUSTOM_CERTIFICATES_HOSTNAME=

#NGINX_CACHE_AGE=1y
#NGINX_CACHE_FILES="js|css|jpg|jpeg|png|gif|ico|swf|webp|svg"

#######################
# MySql #
#######################
Expand Down
3 changes: 3 additions & 0 deletions storage/app/env/PlainPhp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ NGINX_ROOT=/var/www
#NGINX_CUSTOM_CERTIFICATES_FOLDER=
#NGINX_CUSTOM_CERTIFICATES_HOSTNAME=

#NGINX_CACHE_AGE=1y
#NGINX_CACHE_FILES="js|css|jpg|jpeg|png|gif|ico|swf|webp|svg"

#######################
# MySql #
#######################
Expand Down
1 change: 0 additions & 1 deletion storage/app/env/Wordpress
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ NGINX_PORT=80
NGINX_PORT_SSL=443



#######################
# MySql #
#######################
Expand Down

0 comments on commit e028895

Please sign in to comment.