Skip to content

Instantly share code, notes, and snippets.

@codex5
Last active December 4, 2020 09:26
Show Gist options
  • Save codex5/7f9545c96bbe989d63f22aeb154c0b45 to your computer and use it in GitHub Desktop.
Save codex5/7f9545c96bbe989d63f22aeb154c0b45 to your computer and use it in GitHub Desktop.
Varnish: 6081
Nginx: 8080, 443, 80
Varnish Backend
server {
server_name {SERVERNAMES};
listen 8080;
set $MAGE_ROOT /home/{USER}/public_html/magento;
set $MAGE_MODE production;
set $MAGE_RUN_TYPE null;
set $MAGE_RUN_CODE null;
set $HTTPS_FORWARD on;
set $FPM_USER {USER};
# access and error logging for this vhost by using the logwatch logformat
access_log /home/{USER}/log/nginx/access.log logwatch;
error_log /home/{USER}/log/nginx/error.log error;
location ~ \.php$ {
fastcgi_pass unix:/var/run/{USER}.sock;
include include.d/fastcgi_magento2.conf;
}
include include.d/magento2.conf;
}
Update Magento sample configuration file
# PHP entry point for main application
location ~ (index|get|static|report|404|503)\.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Modified
location ~ (index|get|static|report|404|503|health_check)\.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/$FPM_USER.sock;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_param MAGE_MODE $MAGE_MODE;
fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
fastcgi_param HTTPS $HTTPS_FORWARD;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
HTTPS termination & Varnish proxy
server {
listen 443 ssl;
server_name {DOMAINS};
ssl on;
ssl_certificate /etc/letsencrypt/live/{DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{DOMAIN}/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';
keepalive_timeout 300s;
location / {
proxy_pass http://127.0.0.1:6081;
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;
}
}
server {
listen 80;
server_name {DOMAINS};
return 301 https://$host$request_uri;
}
503 fetch failed issue:
- Change /pub/health_check.php to /health_check.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment