Skip to content

Instantly share code, notes, and snippets.

@erfantonjoo
Last active May 30, 2025 11:12
Show Gist options
  • Save erfantonjoo/861919bd58899845b9f2228b41fa6025 to your computer and use it in GitHub Desktop.
Save erfantonjoo/861919bd58899845b9f2228b41fa6025 to your computer and use it in GitHub Desktop.
suarasurabaya config nginx
set $skip_cache 0;
set $debug_skip_exclude_uris "false";
set $debug_skip_exclude_cookies "false";
# 3600 for Wordpress / 300 for other framework
# WordPress cache busting can be controlled using nginx helper
set $expiry_cache 300;
set $mobile '';
if ($http_user_agent ~* '(iPhone|iPod|incognito|webmate|Android|dream|CUPCAKE|froyo|BlackBerry|webOS|s8000|bada|IEMobile|Googlebot\-Mobile|AdsBot\-Google)') {
set $mobile "?smartphone:";
}
# set $clean_args $is_args$clean_args;
# if ($clean_args ~ ^\?$) {
# set $clean_args "";
# }
# End Clean UTM
# Cache exception
### POST requests
if ($request_method = POST) {
set $skip_cache 1;
}
## Query String
### If need to cache query string
if ($args != "") {
set $expiry_cache 300;
# set $skip_cache 1;
}
#### Cached query string
#if ($args ~* 'pages=|page=') {
# set $skip_cache 0;
#}
### Don't cached when this query string exist
#if ($args ~* '') {
# set $skip_cache 1;
#}
## Cookie
### WordPress
if ($http_cookie ~* 'comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in') {
set $debug_skip_exclude_cookies "true";
set $skip_cache 1;
}
### Extras
# if ($http_cookie ~* '') {
# set $debug_skip_exclude_cookies "true";
# set $skip_cache 1;
# }
## Exclude page / url
### WordPress Default
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
### Extras
if ($request_uri ~* '/internal-access-rek') {
set $skip_cache 1;
}
### Penyiar ajax
if ($request_uri ~* '/get_penyiar_active') {
set $expiry_cache 30;
}
### ADD YOUR MONITORING BOT HERE
if ($http_user_agent ~* '(UptimeRobot|Pingdom)') {
set $skip_cache 1;
}
# End Cache exception
## Try Files
location / {
set $real_uri $args;
try_files $uri $uri/ /index.php?$args;
}
# Redis Fetch and Store
location /redis-fetch {
internal ;
set $redis_key $args;
## Change into your redis server
redis_pass 127.0.0.1:6379;
}
location /redis-store {
internal ;
set_unescape_uri $redis_key $arg_key ;
redis2_query set $redis_key $echo_request_body;
## Set expiry time for cached result
redis2_query expire $redis_key $expiry_cache;
## Change into your redis server
redis2_pass 127.0.0.1:6379;
}
# End Redis Fetch and Store
# PHP
location ~ \.php$ {
limit_req zone=req_blacklist burst=10 nodelay;
limit_req zone=req_whitelist burst=20 nodelay;
limit_conn conn_blacklist 40;
limit_conn conn_whitelist 80;
set $redis_key "nginx-cache:$scheme$request_method$host$request_uri$mobile";
try_files $uri =404;
srcache_fetch_skip $skip_cache;
srcache_store_skip $skip_cache;
srcache_response_cache_control off;
set_escape_uri $escaped_key $redis_key;
srcache_fetch GET /redis-fetch $redis_key;
srcache_store PUT /redis-store key=$escaped_key;
# Debugging
#add_header X-Debug-skip $request_body always;
add_header X-Debug-Cache-Fetch $srcache_fetch_status always;
add_header X-Debug-Cache-Store $srcache_store_status always;
add_header X-Debug-Cache-Key $redis_key always;
add_header X-Debug-Cache-Expiry $expiry_cache always;
add_header X-Debug-Message-Request-Uri $request_uri always;
add_header X-Debug-Message-Uri $uri always;
add_header X-Debug-Message-Exclude-Cookie $debug_skip_exclude_cookies always;
#Penting karena redis tidak menerima gzip
fastcgi_param HTTP_ACCEPT_ENCODING "";
include fastcgi_params;
#fastcgi_pass php71;
fastcgi_pass php81;
# Http2 push if neededd
http2_push_preload on;
}
# End PHP
server {
listen 80;
server_name www.suarasurabaya.net suarasurabaya.net;
#location ^~ /adv/webview_video.php {
# proxy_pass http://stream.suarasurabaya.net/webview_video.php;
#}
location ^~ /adv {
proxy_pass https://www.suarasurabaya.net/adv;
}
location ^~ /_watermark {
proxy_pass https://www.suarasurabaya.net/_watermark;
}
location ^~ /v04 {
proxy_pass https://www.suarasurabaya.net/v04;
}
#location ^~ /radio/ini.php {
# proxy_pass https://stream.suarasurabaya.net/ini.php;
#}
#location ^~ /radio/lihat2.php {
#proxy_pass https://stream.suarasurabaya.net/lihat2.php;
#}
location ^~ /survey {
proxy_pass https://www.suarasurabaya.net/survey;
}
location ^~ /sshut {
proxy_pass https://www.suarasurabaya.net/sshut;
}
location ^~ /v05 {
proxy_pass https://www.suarasurabaya.net/v05;
}
location ^~ /radio/player {
proxy_pass https://www.suarasurabaya.net/radio/player;
}
location / {
return 301 https://www.suarasurabaya.net$request_uri;
}
}
server {
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.suarasurabaya.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.suarasurabaya.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
server_name suarasurabaya.net;
return 301 https://www.suarasurabaya.net$request_uri;
}
server {
server_name www.suarasurabaya.net;
access_log /var/log/nginx/suarasurabaya.net.access.log ;
error_log /var/log/nginx/suarasurabaya.net.error.log;
root /var/www/suarasurabaya.net/htdocs;
#real cloudflare
set_real_ip_from 0.0.0.0/0;
real_ip_header CF-Connecting-IP;
index index.php index.html index.htm;
include common/nginx-webp.conf;
include common/tonjoo-security.conf;
include common/php81-cache.conf;
include common/locations-php81.conf;
include common/nginx-cache.conf;
include /var/www/suarasurabaya.net/conf/nginx/*.conf;
#location ^~ /adv/webview_video.php {
#proxy_pass http://stream.suarasurabaya.net/webview_video.php;
#}
location ^~ /adv {
proxy_pass https://www.suarasurabaya.net/adv;
}
location ^~ /_watermark {
proxy_pass https://www.suarasurabaya.net/_watermark;
}
location ^~ /v04 {
proxy_pass https://www.suarasurabaya.net/v04;
}
#location ^~ /radio/ini.php {
#proxy_pass https://stream.suarasurabaya.net/ini.php;
# }
#location ^~ /radio/lihat2.php {
# proxy_pass https://stream.suarasurabaya.net/lihat2.php;
#}
location ^~ /survey {
proxy_pass https://www.suarasurabaya.net/survey;
}
location ^~ /sshut {
proxy_pass https://www.suarasurabaya.net/sshut;
}
location ^~ /v05 {
proxy_pass https://www.suarasurabaya.net/v05;
}
location ^~ /radio/player {
proxy_pass https://www.suarasurabaya.net/radio/player;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.suarasurabaya.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.suarasurabaya.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
# Rewrites for Yoast SEO XML Sitemap
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/sitemap-news.xml$ /index.php?sitemap=1 last;
rewrite ^/sitemap.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment