Skip to content

Commit

Permalink
Varnish support
Browse files Browse the repository at this point in the history
Ssl proxy
Magento production mode
  • Loading branch information
apedik committed Sep 13, 2023
1 parent 26e799a commit 8971790
Show file tree
Hide file tree
Showing 6 changed files with 651 additions and 251 deletions.
1 change: 0 additions & 1 deletion bin/docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ if [[ "$PWD" == *"docker-stack"* || "$PWD" == *"htdocs"* ]]; then
else
${REAL_DOCKER_COMPOSE_CMD} ${BASH_ARGVS[*]};
fi

2 changes: 1 addition & 1 deletion docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
listen 80;
listen 8080;
server_name _;

access_log /var/log/nginx/default.access.log main;
Expand Down
146 changes: 143 additions & 3 deletions docker/nginx/m-servers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,141 @@
# Magento 2 focused PHP hosts
server {
listen 80;
# Docker DNS resolver is .11, NOT A MISTAKE
resolver 127.0.0.11 ipv6=off;

server_name ~^.*\.(loc|local|localhost)$;

error_log /dev/stdout;
access_log /dev/stdout;

# Magento Vars
set $MAGE_MODE production; # or production or developer

root /var/www/htdocs/${http_host}${root_subfolder};

index index.php;
autoindex off;
charset off;
client_max_body_size 20M;

add_header 'X-Content-Type-Options' 'nosniff';
add_header 'X-XSS-Protection' '1; mode=block';

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

location /pub {
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
deny all;
}
set $php_host ${PHP_HOSTM2};
alias /var/www/htdocs/eg-m2-opensource.loc/pub;
add_header X-Frame-Options "SAMEORIGIN";
}

location /static/ {
if ($MAGE_MODE = "production") {
expires max;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;

if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;

if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
add_header X-Frame-Options "SAMEORIGIN";
}

location /media/ {
try_files $uri $uri/ =404;

location ~ ^/media/theme_customization/.*\.xml {
deny all;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
try_files $uri $uri/ =404;
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
try_files $uri $uri/ =404;
}
add_header X-Frame-Options "SAMEORIGIN";
}

location /media/customer/ {
deny all;
}

location /media/downloadable/ {
deny all;
}

location /media/import/ {
deny all;
}

location ~ cron\.php {
deny all;
}

location ~ (index|url|messages|test|get|static|report|404|503)\.php$ {
try_files $uri =404;
set $php_host ${PHP_HOSTM2};
fastcgi_pass unix:/tmp/${php_host}-fpm.sock;

fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=256M \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_buffers 16 256k;
fastcgi_buffer_size 256k;

fastcgi_param MAGE_MODE $MAGE_MODE;
fastcgi_param MAGE_RUN_TYPE store;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE auto_prepend_file=$PHP_PREPENDM2;
include fastcgi_params;
}

# mftf magento cli support
location ~* ^/dev/tests/acceptance/utils($|/) {
root /var/www/htdocs/${http_host}/;
location ~ ^/dev/tests/acceptance/utils/command.php {
set $php_host ${PHP_HOSTM2};
fastcgi_pass unix:/tmp/${php_host}-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
server {
listen 443 ssl;
http2 on;
# Docker DNS reolver is .11, NOT A MISTAKE
Expand All @@ -18,7 +153,7 @@ server {
access_log /dev/stdout;

# Magento Vars
set $MAGE_MODE developer; # or production or developer
set $MAGE_MODE production; # or production or developer

root /var/www/htdocs/${http_host}${root_subfolder};

Expand All @@ -34,7 +169,6 @@ server {
root /var/www/htdocs/${http_host}/;
location ~ ^/setup/index.php {
set $php_host ${PHP_HOSTM2};
# fastcgi_pass ${PHP_HOSTM2}:9000;
fastcgi_pass unix:/tmp/${php_host}-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Expand All @@ -56,7 +190,6 @@ server {
location ~ ^/update/index.php {
fastcgi_split_path_info ^(/update/index.php)(/.+)$;
set $php_host ${PHP_HOSTM2};
# fastcgi_pass ${PHP_HOSTM2}:9000;
fastcgi_pass unix:/tmp/${php_host}-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Expand All @@ -76,6 +209,13 @@ server {

location / {
try_files $uri $uri/ /index.php?$args;
set $varnish_upstream varnish;
proxy_pass http://$varnish_upstream:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}

location /pub {
Expand Down
1 change: 0 additions & 1 deletion docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

user nginx;
worker_processes 1;

Expand Down
Loading

0 comments on commit 8971790

Please sign in to comment.