Skip to content

Instantly share code, notes, and snippets.

@kraba
Last active June 4, 2020 06:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kraba/db74f4976ff20dbb15ac4d0935c2bb40 to your computer and use it in GitHub Desktop.
Save kraba/db74f4976ff20dbb15ac4d0935c2bb40 to your computer and use it in GitHub Desktop.
server {
listen 80;
server_name awstat.mysite.com;
root /var/www/stat;
error_log /var/log/nginx/awstat.mysite.com.error;
access_log /var/log/nginx/awstat.mysite.com.access;
log_not_found off;
server_tokens off;
error_page 401 403 404 /404.html;
location ^~ /icon {
alias /usr/local/awstats/wwwroot/icon/;
}
location ^~ /css/ {
alias /usr/local/awstats/wwwroot/css/;
}
# beautifying the url
location ~ ^/([a-z0-9-_\.]+)$ {
return 301 $scheme://awstats.mysite.org/cgi-bin/awstats.pl?config=$1;
}
location ~ ^/cgi-bin/(awredir|awstats)\.pl {
gzip off;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME /etc/nginx/cgi-bin.php;
fastcgi_param X_SCRIPT_FILENAME /usr/local/awstats/wwwroot$fastcgi_script_name;
fastcgi_param X_SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}
<?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