Last active
January 28, 2022 07:38
-
-
Save noogen/7901bb113c529aa9b1689ec7a9bc863c to your computer and use it in GitHub Desktop.
nginx hit counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
#NGINX_INSERT0; | |
#NGINX_INSERT1; | |
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") { | |
set $year $1; | |
set $month $2; | |
set $day $3; | |
set $hour $4; | |
set $minutes $5; | |
set $seconds $6; | |
} | |
access_log /var/log/nginx/$year-$month-$day.$hour-$minutes.hc-access.log; | |
root /var/www/html; | |
#NGINX_INSERT2; | |
# Add index.php to the list if you are using PHP | |
index index.html index.htm index.nginx-debian.html; | |
server_name _; | |
#NGINX_INSERT3; | |
location ~ /pi/([a-z0-9-]+)/([A-Za-z0-9-]+)([/]*) { | |
if ($arg_ua ~* ^-?[0-9]\d*(\.\d+)?$) { | |
return 301 https://www.google-analytics.com/collect?cid=$1.$pid&z=$msec&v=1&t=event&tid=UA-$arg_ua&ev=1&ec=$1&ea=$2&el=$arg_el; | |
} | |
add_header Access-Control-Allow-Origin "*"; | |
empty_gif; | |
} | |
# the blackhole | |
location ~ /null/(.*) { | |
add_header Access-Control-Allow-Origin "*"; | |
empty_gif; | |
} | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to displaying a 404. | |
try_files $uri $uri/ =404; | |
} | |
#NGINX_INSERT4; | |
} | |
server { | |
listen 443 default_server; | |
listen [::]:443 default_server; | |
#NGINX_INSERT0; | |
ssl on; | |
ssl_certificate /app/etc/nginx/ssl/example.pem; | |
ssl_certificate_key /app/etc/nginx/ssl/example.key; | |
#NGINX_INSERT1; | |
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") { | |
set $year $1; | |
set $month $2; | |
set $day $3; | |
set $hour $4; | |
set $minutes $5; | |
set $seconds $6; | |
} | |
access_log /var/log/nginx/$year-$month-$day.$hour-$minutes.hc-access.log; | |
root /var/www/html; | |
#NGINX_INSERT2; | |
# Add index.php to the list if you are using PHP | |
index index.html index.htm index.nginx-debian.html; | |
server_name _; | |
#NGINX_INSERT3; | |
location ~ /pi/([a-z0-9-]+)/([A-Za-z0-9-]+)([/]*) { | |
if ($arg_ua ~* ^-?[0-9]\d*(\.\d+)?$) { | |
return 301 https://www.google-analytics.com/collect?cid=$1.$pid&z=$msec&v=1&t=event&tid=UA-$arg_ua&ev=1&ec=$1&ea=$2&el=$arg_el; | |
} | |
add_header Access-Control-Allow-Origin "*"; | |
empty_gif; | |
} | |
# the blackhole | |
location ~ /null/(.*) { | |
add_header Access-Control-Allow-Origin "*"; | |
empty_gif; | |
} | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to displaying a 404. | |
try_files $uri $uri/ =404; | |
} | |
#NGINX_INSERT4; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment