Example Case use for ReactJS with Python Flask
upstream BackEnd {
ip_hash;
server 127.0.0.1:8085;
# port untuk applikasi backend
}
server {
listen 80;
server_name www.domain.id;
index index.html;
# Web Static
# contoh path untuk CRA
root /home/user/frontend/build;
charset utf-8;
location / {
try_files $uri $uri/ /index.html;
}
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
# Jika menggunakan PWA
location index.html {
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
}
# Jika menggunakan PWA
location service-worker.js {
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
}
# Contoh untuk ReactJS
location ^~ /static/ {
autoindex on;
gzip_static on;
include /etc/nginx/mime.types;
}
# Contoh handle url untuk api yang menggunakan uwsgi/wsgi
# contoh dibawah saya gunakan untuk Backend menggunakan
# python Flask (Supervisor + Flask + wsgi)
location ~ ^/(api|media|auth)/{
root /home/user/backend/apps;
include uwsgi_params;
uwsgi_pass BackEnd;
uwsgi_read_timeout 100000;
}