Merge branch 'master' of ateliers.heureux-cyclage.org:lhc/ateliers
authorLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Fri, 19 Apr 2013 01:52:15 +0000 (03:52 +0200)
committerLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Fri, 19 Apr 2013 01:52:15 +0000 (03:52 +0200)
20 files changed:
etc/mysql/bin/createdb
etc/mysql/bin/createuser
etc/mysql/my.cnf
etc/nginx/conf.d/fastcgi.conf
etc/nginx/nginx.conf
etc/nginx/site.d/gitweb/site.conf
etc/nginx/site.d/lhc-questionnaires/configure.sh
etc/nginx/site.d/lhc-questionnaires/site.conf
etc/nginx/site.d/lhc-stats-tls/local.conf
etc/nginx/site.d/lhc-stats/configure.sh
etc/nginx/site.d/lhc-stats/http.conf [new file with mode: 0644]
etc/nginx/site.d/lhc-stats/local.conf
etc/nginx/site.d/lhc-stats/site.conf
etc/nginx/site.d/lhc-www/configure.sh
etc/nginx/site.d/lhc-www/site.conf
etc/nginx/site.d/sympa/site.conf
etc/sv/mysql/configure.sh
etc/sv/nginx/configure.sh
etc/sv/nginx/run
etc/sv/php5-fpm/configure.sh

index 582051b..adc6ecd 100755 (executable)
@@ -1,9 +1,6 @@
 #!/bin/sh -eux
 db="$1"
-user="$2"
-sudo -u mysql mysql --batch <<-EOF
-       DROP   DATABASE IF EXISTS $db;
-       CREATE DATABASE $db CHARACTER SET utf8 COLLATE utf8_general_ci;
-       GRANT ALL PRIVILEGES ON $base.* TO '$user'@'localhost' IDENTIFIED WITH auth_socket;
-       FLUSH PRIVILEGES;
+user="${2:-$1}"
+sudo -u mysql mysql --batch --verbose <<-EOF
+       CALL mysql.create_database('$db', '$user', 'localhost');
        EOF
index 041495e..1b234fa 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh -eux
 user="$1"
-sudo -u mysql mysql -u mysql --verbose --batch <<-EOF
+sudo -u mysql mysql -u mysql --batch --verbose <<-EOF
        CALL mysql.create_user('$user', 'localhost');
        EOF
 sudo adduser "$user" mysql-data
index fb1b3cb..2e43584 100644 (file)
@@ -1,5 +1,5 @@
 [client]
-local-infile = 0
+#local-infile = 0
 port = 3306
 socket = /run/mysqld/sock/mysql
 [mysqld_safe]
index 72a1588..fdc5f6d 100644 (file)
@@ -1,10 +1,11 @@
 ## DOC: http://wiki.nginx.org/HttpFastcgiModule
 fastcgi_buffer_size 128k;
-fastcgi_buffers 4 256k;
+fastcgi_buffers 256 4k;
 fastcgi_busy_buffers_size 256k;
 fastcgi_connect_timeout 60;
 fastcgi_ignore_client_abort off;
 fastcgi_intercept_errors on;
+fastcgi_max_temp_file_size 2M;
 fastcgi_param CONTENT_LENGTH    $content_length;
 fastcgi_param CONTENT_TYPE      $content_type;
 fastcgi_param DOCUMENT_ROOT     $document_root;
@@ -30,3 +31,5 @@ fastcgi_param SERVER_SOFTWARE   nginx/$nginx_version;
 fastcgi_read_timeout 180;
 fastcgi_send_timeout 180;
 fastcgi_temp_file_write_size 256k;
+
+# vim: ft=sh
index 220c1f4..216e273 100644 (file)
@@ -21,13 +21,16 @@ http {
        default_type application/octet-stream;
        error_log /var/log/nginx/error.log warn;
        error_page 403 = 404;
-       fastcgi_cache_key "$request_method $scheme://$host$request_uri";
+       fastcgi_cache_key "$request_method $scheme://$http_host$request_uri";
        fastcgi_cache_path /run/shm/cache/nginx/fastcgi
+        inactive=10m
+        keys_zone=microcache:2M
         levels=1:2
-        keys_zone=microcache:10m
-        inactive=5m
-        max_size=64m;
-       fastcgi_cache microcache;
+        loader_files=100000
+        loader_sleep=1
+        loader_threshold=2592000000
+        max_size=64M;
+       fastcgi_temp_path /run/shm/tmp/nginx/ 1 2;
        gzip on;
        gzip_buffers 16 8k;
        gzip_comp_level 6;
@@ -78,6 +81,22 @@ http {
                #       This is useful for prepending headers before calling sendfile,
                #       or for throughput optimization.
        types_hash_max_size 2048;
+       ## Add here all user agents that are to be blocked.
+       map $http_user_agent $bad_bot {
+               default 0;
+               libwww-perl                      1;
+               ~(?i)(httrack|htmlparser|libwww) 1;
+        }
+       ## Add here all referrers that are to blocked.
+       #map $http_referer $bad_referer {
+       #       default 0;
+       #       ~(?i)(babes|casino|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|replica|sex|teen|webcam|zippo) 1;
+       # }
+       geo $not_local {
+               default 1;
+               127.0.0.1 0;
+        }
+       include /etc/nginx/site.d/*/http.conf;
        include /etc/nginx/site.d/*/server.conf;
  }
 pid /run/nginx.pid;
index d27614c..70fb600 100644 (file)
@@ -51,7 +51,6 @@ location @gitweb {
        fastcgi_cache_valid 200 10s;
        fastcgi_cache_valid 404 30m;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
-       fastcgi_max_temp_file_size 2M;
        fastcgi_no_cache $no_cache;
        fastcgi_param GITWEB_CONFIG /etc/gitweb/gitweb.conf;
        fastcgi_param PATH_INFO $uri;
index 680d101..e407240 100644 (file)
@@ -1,4 +1,5 @@
-sudo adduser lhc_quest__php5 www-"$site"
+pool=lhc_quest
+sudo adduser php5_"$pool" www-"$site"
 sudo adduser www-"$site"-tls www-"$site"
-~mysql/bin/createuser lhc_quest__php5
-
+~mysql/bin/createuser php5_"$pool"
+~mysql/bin/createdb   php5_"$pool"
index f0e1134..bd4365d 100644 (file)
@@ -40,7 +40,6 @@ location ~ \.php$ {
        fastcgi_cache_valid 404 10m;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_index index.php;
-       fastcgi_max_temp_file_size 2M;
        fastcgi_no_cache $no_cache;
        fastcgi_param REDIRECT_STATUS 200;
                # NOTE: PHP only, required if PHP was built with --enable-force-cgi-redirect
index 1d12581..d81e006 100644 (file)
@@ -2,3 +2,24 @@ listen 443;
 include /etc/nginx/conf.d/ssl.conf;
 ssl_certificate     /etc/nginx/x509.d/lhc-stats-tls/crt.pem;
 ssl_certificate_key /etc/nginx/x509.d/lhc-stats-tls/key.pem;
+
+location = /index.php {
+ ## Relay all index.php requests to fastcgi.
+       include /etc/nginx/conf.d/fastcgi.conf;
+       add_header X-Piwik-Cache $upstream_cache_status;
+       expires epoch;
+       fastcgi_cache microcache;
+       fastcgi_cache_bypass $no_cache;
+       fastcgi_cache_use_stale error timeout invalid_header updating http_500;
+       fastcgi_cache_valid 200 301 5m;
+       fastcgi_cache_valid 302 3m;
+       fastcgi_cache_valid 404 1m;
+       fastcgi_ignore_headers Cache-Control Expires;
+       fastcgi_index index.php;
+       fastcgi_no_cache $no_cache;
+       fastcgi_param REDIRECT_STATUS 200;
+       
+       fastcgi_pass php5_fpm_lhc_stats;
+ }
+
+# vim: ft=sh
index 3ab7902..31bc2be 100644 (file)
@@ -1,4 +1,5 @@
-sudo adduser lhc_stats__php5 www-"$site"
+pool=lhc_stats
+sudo adduser php5_"$pool" www-"$site"
 sudo adduser www-"$site"-tls www-"$site"
-~mysql/bin/createuser lhc_stats__php5
-
+~mysql/bin/createuser php5_"$pool"
+~mysql/bin/createdb   php5_"$pool"
diff --git a/etc/nginx/site.d/lhc-stats/http.conf b/etc/nginx/site.d/lhc-stats/http.conf
new file mode 100644 (file)
index 0000000..58563f7
--- /dev/null
@@ -0,0 +1,28 @@
+upstream php5_fpm_lhc_stats {
+       server unix:/run/php5/fpm/lhc_stats;
+ }
+
+map $request_method $no_cache {
+ # NOTE: if non GET/HEAD, don't cache.
+       default 1;
+       HEAD 0;
+       GET  0;
+ }
+map $arg_module $no_cache {
+ ## When we go through installation
+ ## or when we're on the dashboard for specific tasks.
+       Installation 1; # when invoking the installation module.
+       ~[^\&]*(?:Dashboard|Live|Goals|Admin|Manager) 1; # some tasks
+ }
+map $arg_action $no_cache {
+ ## The first installation steps don't invoke the installation module.
+       systemCheck 1;
+       databaseSetup 1;
+ }
+map $http_cookie $no_cache {
+ ## Testing for the session cookie being present.
+ ## If there is then no caching is to be done.
+       ~PIWIK_SESSID 1; # Piwik session cookie
+ }
+
+# vim: ft=sh
index 56b9f1c..b5f622c 100644 (file)
@@ -1 +1,5 @@
 listen 80;
+
+location = /index.php {
+       return 302 "https://$http_host/index.php";
+ }
index b52ba28..a98a1a1 100644 (file)
@@ -2,50 +2,79 @@ server_name stats.heureux-cyclage.org;
 
 client_body_buffer_size 8k;
 client_max_body_size 10m;
-location / {
-       index index.html index.htm index.php;
+
+if ($bad_bot) {
+       return 444;
  }
-location ~* ^.+.(css|gif|html|ico|jpeg|js|jpg|png|txt|xml)$ {
-       access_log off;
-       expires 30d;
-       log_not_found off;
+#if ($bad_referer) {
+#      return 444;
+# }
+
+#location ~ /\. {
+#      access_log off;
+#      deny all;
+#      log_not_found off;
+# }
+location ~* ^.+\.(?:css|gif|jpe?g|js|png|swf)$ {
+ ## Defining the valid referers.
+       ## Disallow any usage of piwik assets if referer is non valid.
+       valid_referers none blocked
+        *.cyclocoop.org
+        *.heureux-cyclage.org
+        *.ptitvelo.net
+        *.velosenville.org;
+       if ($invalid_referer)  {
+               return 444;
+        }
+       
+       expires max;
+       # NOTE: Static files use the OS buffer cache.
+       open_file_cache max=500 inactive=120s;
+       open_file_cache_errors off;
+       open_file_cache_min_uses 2;
+       open_file_cache_valid 45s;
+       tcp_nodelay off;
+ }
+location = /favicon.ico {
+ ## Support for favicon. Return a 204 (No Content) if the favicon doesn't exist.
+       try_files /favicon.ico =204;
  }
-location ~ /\. {
-       access_log off;
-       deny all;
-       log_not_found off;
+location / {
+ ## Try all locations and relay to index.php as a fallback.
+       try_files $uri /index.php?$query_string;
  }
-location ~ \.php$ {
+location = /piwik.php {
+ ## Relay all piwik.php requests to fastcgi.
        include /etc/nginx/conf.d/fastcgi.conf;
-       set $no_cache "0";
-       if ($request_method !~ ^(GET|HEAD)$) {
-        # NOTE: if non GET/HEAD, don't cache and mark user as uncacheable for 1 second via cookie.
-               set $no_cache "1";
-        }
-       if ($no_cache = "1") {
-        # NOTE: drop no cache cookie if need be (for some reason, add_header fails if included in prior if-block).
-               add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
-               add_header X-Microcachable "0";
-        }
-       if ($http_cookie ~* "_mcnc") {
-        # NOTE: bypass cache if no-cache cookie is set
-               set $no_cache "1";
-        }
+       add_header X-Piwik-Long-Cache $upstream_cache_status;
+       expires epoch;
+       fastcgi_cache microcache;
        fastcgi_cache_bypass $no_cache;
-       fastcgi_cache_use_stale updating;
-       fastcgi_cache_valid 200 10s;
+       fastcgi_cache_use_stale error timeout invalid_header updating http_500;
+       fastcgi_cache_valid 200 301 2h;
+       fastcgi_cache_valid 302 30m;
        fastcgi_cache_valid 404 10m;
-       fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
-       fastcgi_index index.php;
-       fastcgi_max_temp_file_size 2M;
+       fastcgi_ignore_headers Cache-Control Expires;
        fastcgi_no_cache $no_cache;
        fastcgi_param REDIRECT_STATUS 200;
-               # NOTE: PHP only, required if PHP was built with --enable-force-cgi-redirect
-       fastcgi_pass_header Cookie;
-       fastcgi_pass_header Set-Cookie;
-       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        
-       fastcgi_pass unix:/run/php5/fpm/lhc_stats;
+       fastcgi_pass php5_fpm_lhc_stats;
+ }
+location ~* ^.+\.php$ {
+ ## Any other attempt to access PHP files redirects to the root.
+       return 302 /;
+ }
+location ~* (?:DESIGN|(?:gpl|README|LICENSE)[^.]*|LEGALNOTICE)(?:\.txt)*$ {
+ ## Redirect to the root if attempting to access a txt file.
+       return 302 /;
+ }
+location ~* \.(?:bat|html?|git|ini|sh|svn[^.]*|txt|tpl|xml)$ {
+ ## Disallow access to several helper files.
+       return 404;
+ }
+location = /robots.txt {
+ ## No crawling of this site for bots that obey robots.txt.
+       return 200 "User-agent: *\nDisallow: /\n";
  }
 
 # vim: ft=sh
index b9bbd2a..8df0091 100644 (file)
@@ -1,2 +1,2 @@
-sudo adduser lhc_www__php5 www-"$site"
+sudo adduser php5_lhc_www www-"$site"
 sudo adduser www-"$site"-tls www-"$site"
index 5eabe39..13786a6 100644 (file)
@@ -37,7 +37,6 @@ location ~ \.php$ {
        fastcgi_cache_valid 404 10m;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_index index.php;
-       fastcgi_max_temp_file_size 2M;
        fastcgi_no_cache $no_cache;
        fastcgi_param REDIRECT_STATUS 200;
                # NOTE: PHP only, required if PHP was built with --enable-force-cgi-redirect
index 7fd9353..d627aa4 100644 (file)
@@ -31,7 +31,6 @@ location / {
        fastcgi_cache_valid 200 10s;
        fastcgi_cache_valid 404 30m;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
-       fastcgi_max_temp_file_size 2M;
        fastcgi_no_cache $no_cache;
        fastcgi_param SCRIPT_NAME '';
        fastcgi_param SERVER_NAME $host;
index 29a8c9d..96b40ea 100644 (file)
@@ -67,6 +67,7 @@ do sleep 1; done
 #   DELETE FROM mysql.user WHERE user = 'root' AND host NOT IN ('localhost', '127.0.0.1', '::1');
 sudo mysql -u root --batch --verbose <<-EOF
        DELETE FROM mysql.user WHERE user = 'root' and plugin = '';
+       
        DROP PROCEDURE IF EXISTS mysql.create_user_mysql;
        DELIMITER //
        CREATE PROCEDURE mysql.create_user_mysql ()
@@ -85,20 +86,40 @@ sudo mysql -u root --batch --verbose <<-EOF
        UPDATE mysql.user SET grant_priv='Y',super_priv='Y' WHERE user='mysql';
        DELETE FROM mysql.db   WHERE user = '';
        DELETE FROM mysql.user WHERE user = '';
+       
        DROP PROCEDURE IF EXISTS mysql.create_user;
        CREATE PROCEDURE mysql.create_user (username VARCHAR(16), hostname VARCHAR(60))
-                       BEGIN
-                               IF NOT (EXISTS (SELECT User
-                                       FROM mysql.user
-                                       WHERE User = username
-                                       AND Host = hostname
-                                       LIMIT 1))
-                                THEN
-                                       SET @QUERY = CONCAT("CREATE USER ", username, "@", hostname, " IDENTIFIED WITH auth_socket");
-                                       PREPARE stmt FROM @QUERY;
-                                       EXECUTE stmt;
-                                END IF;
-                        END;
+               BEGIN
+                       IF NOT (EXISTS (SELECT User
+                               FROM mysql.user
+                               WHERE User = username
+                               AND Host = hostname
+                               LIMIT 1))
+                        THEN
+                               SET @QUERY = CONCAT("CREATE USER ", username, "@", hostname, " IDENTIFIED WITH auth_socket");
+                               PREPARE stmt FROM @QUERY;
+                               EXECUTE stmt;
+                        END IF;
+                END;
+        //
+       
+       DROP PROCEDURE IF EXISTS mysql.create_database;
+       CREATE PROCEDURE mysql.create_database (dbname VARCHAR(16), username VARCHAR(16), hostname VARCHAR(60))
+               BEGIN
+                       IF NOT (EXISTS (SELECT SCHEMA_NAME
+                               FROM INFORMATION_SCHEMA.SCHEMATA
+                               WHERE SCHEMA_NAME = dbname
+                               LIMIT 1))
+                        THEN
+                               SET @QUERY = CONCAT("CREATE DATABASE ", dbname, " CHARACTER SET utf8 COLLATE utf8_general_ci");
+                               PREPARE stmt FROM @QUERY;
+                               EXECUTE stmt;
+                        END IF;
+                       SET @QUERY = CONCAT("GRANT ALL PRIVILEGES ON ", dbname, ".* TO ", username, "@", hostname);
+                       PREPARE stmt FROM @QUERY;
+                       EXECUTE stmt;
+                END;
         //
+       
        FLUSH PRIVILEGES;
        EOF
index 7b2b546..a44c647 100644 (file)
@@ -53,25 +53,36 @@ for site in $(find "$tool"/etc/nginx/site.d \
         /etc/nginx/site.d/"$site"
        sudo install -d -m 770 -o www -g www \
         /etc/nginx/x509.d/"$site"
-       test -L /home/www/pub/"$site" ||
+       sudo test -L /home/www/pub/"$site" ||
        sudo install -d -m 2770 -o www-"$site" -g www-"$site" \
         /home/www/pub/"$site"
        sudo adduser www-data www-"$site"
        sudo adduser www-data log-www-"$site"
        sudo install -m 660 -o www -g www \
         "$tool"/etc/nginx/site.d/"$site"/local.conf \
-               /etc/nginx/site.d/"$site"/local.inc
+               /etc/nginx/site.d/"$site"/local.conf
+       test ! -e "$tool"/etc/nginx/site.d/"$site"/http.conf ||
        sudo install -m 660 -o www -g www \
-        "$tool"/etc/nginx/site.d/"$site"/site.conf \
-               /etc/nginx/site.d/"$site"/site.inc
+        "$tool"/etc/nginx/site.d/"$site"/http.conf \
+               /etc/nginx/site.d/"$site"/http.conf
+       if test -L "$tool"/etc/nginx/site.d/"$site"/site.conf
+        then
+               sudo cp --force --preserve=links --no-dereference \
+                "$tool"/etc/nginx/site.d/"$site"/site.conf \
+                       /etc/nginx/site.d/"$site"/site.conf
+        else
+               sudo install -m 660 -o www -g www \
+                "$tool"/etc/nginx/site.d/"$site"/site.conf \
+                       /etc/nginx/site.d/"$site"/site.conf
+        fi
        sudo install -m 660 -o www -g www /dev/stdin \
         /etc/nginx/site.d/"$site"/server.conf <<-EOF
                server {
-                       access_log          /home/www/log/$site/nginx/access.log main;
-                       error_log           /home/www/log/$site/nginx/error.log warn;
-                       root                /home/www/pub/$site;
-                       include             /etc/nginx/site.d/$site/local.inc;
-                       include             /etc/nginx/site.d/$site/site.inc;
+                       access_log /home/www/log/$site/nginx/access.log main;
+                       error_log  /home/www/log/$site/nginx/error.log warn;
+                       root       /home/www/pub/$site;
+                       include    /etc/nginx/site.d/$site/local.conf;
+                       include    /etc/nginx/site.d/$site/site.conf;
                 }
                EOF
        (
index 8bc0f31..3b876fb 100755 (executable)
@@ -12,7 +12,8 @@ install -d -m 770 -o www-data -g www-data \
  /run/nginx/fastcgi \
  /run/shm/cache/nginx \
  /run/shm/cache/nginx/fastcgi \
- /run/shm/cache/nginx/client_body
+ /run/shm/cache/nginx/client_body \
+ /run/shm/tmp/nginx
 
 exec /usr/sbin/nginx \
  -c /etc/nginx/nginx.conf \
index 1fdaa54..25187a7 100644 (file)
@@ -45,7 +45,7 @@ for pool in $(find "$tool"/etc/php5/fpm/pool.d/ \
  -false ${@:+$(printf -- '-or -name %s.conf\n' "$@")} \
  -printf '%f\n')
  do pool=${pool%\.conf}
-       rule adduser "$pool"__php5 \
+       rule adduser php5_"$pool" \
         --disabled-login \
         --disabled-password \
         --group \
@@ -76,7 +76,7 @@ for pool in $(find "$tool"/etc/php5/fpm/pool.d/ \
                env[TEMP] = /tmp
                env[TMPDIR] = /tmp
                env[TMP] = /tmp
-               group = ${pool}__php5
+               group = php5_$pool
                #listen = 127.0.0.1:9000
                listen = /run/php5/fpm/$pool
                #listen.allowed_clients = 127.0.0.1
@@ -96,7 +96,7 @@ for pool in $(find "$tool"/etc/php5/fpm/pool.d/ \
                rlimit_core = unlimited
                rlimit_files = 131072
                slowlog = /home/www/log/php5/fpm/$pool/slow.log
-               user = ${pool}__php5
+               user = php5_$pool
                $(cat "$tool"/etc/php5/fpm/pool.d/"$pool".conf)
                EOF
  done