commit 443f3a7f733b40bca77c21e440158473da73a482 Author: by-sabbir Date: Mon Apr 4 02:40:54 2022 +0600 chores: nginx configuration for server and service diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..ceb50d2 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,40 @@ +load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; + +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; + include /etc/nginx/conf.d/*.conf; + + + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + geoip2 /var/lib/GeoIP/GeoLite2-Country.mmdb { + $geoip2_data_country_iso_code country iso_code; + } + + map $geoip2_data_country_iso_code $allowed_country { + default yes; + BD no; + } + log_format main '$geoip2_data_country_iso_code $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; +} diff --git a/conf/site.conf b/conf/site.conf new file mode 100644 index 0000000..867b6ed --- /dev/null +++ b/conf/site.conf @@ -0,0 +1,22 @@ +server { + # Block forbidden country + default_type application/json; + if ($allowed_country = no) { + return 444 '{"code":"444", "message": "Blocked"}'; + } + + location / { + return 200 '{"code":"100", "message": "Not Blocked"}'; + } + error_page 400 404 405 =200 @40*_json; + + location @40*_json { + return 200 '{"code":"1", "message": "Not Found"}'; + } + + error_page 500 502 503 504 =200 @50*_json; + + location @50*_json { + return 200 '{"code":"1", "message": "Unknown Error"}'; + } +}