Skip to content

Instantly share code, notes, and snippets.

@alt-grr
Created November 28, 2019 20:06
Show Gist options
  • Save alt-grr/7349e5fce95df8dadb07b59264ea7eed to your computer and use it in GitHub Desktop.
Save alt-grr/7349e5fce95df8dadb07b59264ea7eed to your computer and use it in GitHub Desktop.
AWStats on Debian 10 with ngnix - separate domain setup
server {
listen 80;
server_name awstats.EXAMPLE.COM;
root /var/www/awstats;
error_log /var/log/nginx/error-awstats.log;
access_log off;
log_not_found off;
location ^~ /awstats-icon {
alias /usr/share/awstats/icon/;
}
location ~ ^/$ {
rewrite ^ /awstats.pl?config=EXAMPLE.COM;
}
location ~ ^.*\\.(cgi|pl|py|rb) {
if ($args ~ "config=([a-z0-9-_\.]+)") {
set $domain $1;
}
auth_basic "Auth";
auth_basic_user_file /etc/awstats/awstats.htpasswd;
gzip off;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index cgi-bin.php;
fastcgi_param SCRIPT_FILENAME /etc/nginx/cgi-bin.php;
fastcgi_param SCRIPT_NAME /cgi-bin/cgi-bin.php;
fastcgi_param X_SCRIPT_FILENAME /usr/lib/cgi-bin$fastcgi_script_name;
fastcgi_param X_SCRIPT_NAME /cgi-bin$fastcgi_script_name;
fastcgi_param REMOTE_USER $remote_user;
}
}
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);
$newenv = $_SERVER;
$newenv["SCRIPT_FILENAME"] = $_SERVER["X_SCRIPT_FILENAME"];
$newenv["SCRIPT_NAME"] = $_SERVER["X_SCRIPT_NAME"];
if (is_executable($_SERVER["X_SCRIPT_FILENAME"])) {
$process = proc_open($_SERVER["X_SCRIPT_FILENAME"], $descriptorspec, $pipes, NULL, $newenv);
if (is_resource($process)) {
fclose($pipes[0]);
$head = fgets($pipes[1]);
while (strcmp($head, "\n")) {
header($head);
$head = fgets($pipes[1]);
}
fpassthru($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
$return_value = proc_close($process);
} else {
header("Status: 500 Internal Server Error");
echo("Internal Server Error");
}
} else {
header("Status: 404 Page Not Found");
echo("Page Not Found");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment