Skip to main content

Single Instance cezerin2-proxy nginx config

nginx.conf

user  nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

keepalive_timeout 65;
sendfile on;
#tcp_nopush on;
#gzip on;

include /etc/nginx/conf.d/*.conf;
}

default.conf.template

server {
# Dynamic image resizing server
listen 127.0.0.1:8888;
server_tokens off;
location ~ "^/resize/(?<entity>\w+)/(?<id>\w+)/(?<width>[1-9][0-9][0-9]{1}|[1][0-9][0-9][0-9]{1})/(?<file>.+)$" {
alias /var/www/cezerin2/public/content/images/$entity/$id/$file;
image_filter_buffer 20M;
image_filter_jpeg_quality 85;
image_filter_interlace on;
image_filter resize $width -;
}
}

# Cache rule for resized images
proxy_cache_path /tmp/nginx-images-cache2/ levels=1:2 keys_zone=images:10m inactive=30d max_size=5g use_temp_path=off;

server {
listen 80;
server_name ${DOMAIN};

gzip on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types application/x-javascript application/javascript application/xml application/json text/xml text/css text$

client_body_timeout 12;
client_header_timeout 12;
reset_timedout_connection on;
send_timeout 10;
server_tokens off;
client_max_body_size 50m;

expires 1y;
access_log off;
log_not_found off;

location / {
try_files $uri @proxy;
}

location @proxy {
# Proxy to NodeJS
expires off;
proxy_pass http://${STORE_HOST};
proxy_set_header Host $host;
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 $scheme;
}
}

server {
listen 80;
server_name admin.${DOMAIN};

gzip on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types application/x-javascript application/javascript application/xml application/json text/xml text/css text$

client_body_timeout 12;
client_header_timeout 12;
reset_timedout_connection on;
send_timeout 10;
server_tokens off;
client_max_body_size 50m;

expires 1y;
access_log off;
log_not_found off;

location / {
try_files $uri @proxy;
}

location @proxy {
# Proxy to NodeJS
expires off;
proxy_pass http://${ADMIN_HOST};
proxy_set_header Host $host;
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 $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

server {
listen 80;
server_name asset.${DOMAIN};

gzip on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types application/x-javascript application/javascript application/xml application/json text/xml text/css text$

client_body_timeout 12;
client_header_timeout 12;
reset_timedout_connection on;
send_timeout 10;
server_tokens off;
client_max_body_size 50m;

expires 1y;
access_log off;
log_not_found off;

location / {
try_files $uri @proxy;
}

location @proxy {
# Proxy to NodeJS
expires off;
proxy_pass http://${ASSET_HOST};
proxy_set_header Host $host;
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 $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

location ~ "^/images/(?<entity>\w+)/(?<id>\w+)/(?<width>[1-9][0-9][0-9]{1}|[1][0-9][0-9][0-9]{1})/(?<file>.+)$" {
# /images/products/id/100/file.jpg >>> Proxy to internal image resizing server
proxy_pass http://127.0.0.1:8888/resize/$entity/$id/$width/$file;
proxy_cache images;
proxy_cache_valid 200 30d;
}
}