Difference between revisions of "Wifi kiosk"

From Kiwix
Jump to navigation Jump to search
(→‎..using Nginx: add comments for kiwix-serve / kiwix-manage usage)
 
(13 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This page is a HOWTO to create a Kiwix '''Wifi kiosk''', a simple wifi hotspot which allow user to surf on Wikipedia using kiwix-serve and also provide all necessary files to download.
This page is a HOWTO to create a Kiwix '''Wifi kiosk''', a simple wifi hotspot which allow user to surf on Wikipedia using [[kiwix-serve]] and also provide all necessary files to download.


== 1 - Hardware ==
== Hardware ==
Almost all hardware may be able to help to build such a wifi hotspot. We use a small PC based on a x86 and using a USB wifi dongle.
Almost all hardware may be able to help to build such a wifi hotspot. We use a small PC based on a x86 and using a USB wifi dongle.
To install Debian on the computer, we use an additional USB HD.
To install Debian on the computer, we use an additional USB HD.


== 2 - OS Installation ==
== OS Installation ==
Install unetbootin and start it. unetbootin propose you to install a debian unstable netinstall on your USB key, do it.
Install unetbootin and start it. unetbootin propose you to install a debian unstable netinstall on your USB key, do it.
Boot your target computer on the usb key and install Debian choosing the options "Web server" and "SSH server".
Boot your target computer on the usb key and install Debian choosing the options "Web server" and "SSH server".


== 3 - Install additional packages ==
== Install additional packages ==
You should now be able to connect to you computer using SSH, you may consequently to all the next steps remotly.
You should now be able to connect to you computer using SSH, you may consequently to all the next steps remotly.
Install the following packags : wireless-tools, dnsmasq
Install the following packags : wireless-tools, dnsmasq
Check that you wirelss card is correctly recognized.
Check that you wirelss card is correctly recognized.


== 4 - Configuration network ==
== Configuration network ==
Add to the /etc/network/interfaces
Add to the /etc/network/interfaces


Line 29: Line 29:
Try to start the interface with: ifconfig wlan0 up
Try to start the interface with: ifconfig wlan0 up


== 5 - Configuration of DNS & DHCP ==
== Configuration of DNS & DHCP ==


Enable the option in /etc/dnsmasq.conf :
Enable the option in /etc/dnsmasq.conf :
Line 39: Line 39:
At this moment you should be able to freely connect to the KIWIX hotspot and your web browser should display for any request the default Apache web page.
At this moment you should be able to freely connect to the KIWIX hotspot and your web browser should display for any request the default Apache web page.


== 6 - Configuration of Apache ==
== Install kiwix-serve with content ==


You have to create a vhost for kiwix in the file /etc/apache2/sites-available/kiwix like following.
Compile and install kiwix-serve or install it from a package.
<source lang="text">
 
Choose the content (ZIM file) you want to serve and index it with kiwix-index.
 
Start kiwix-serve on the port 4201. So you should be typing on your client http://kiwix:4201 get the page served by kiwix-serve.
 
Add the kiwix-serve to the init.d following [http://www.debian-administration.org/articles/28 this documentation].
 
== Integrate kiwix-serve .. ==
=== ..using Apache with mod_proxy ===
 
*Activate mod_proxy with "a2enmod proxy proxy_http rewrite"
*Create a vhost for kiwix in the file /etc/apache2/sites-available/kiwix like the following.
<syntaxhighlight style="margin-left:2em;" lang="apache">
<VirtualHost *:80>
<VirtualHost *:80>
         ServerName kiwix
         ServerName kiwix
         DocumentRoot /var/www/kiwix/
         DocumentRoot /var/www/kiwix/
        RewriteEngine On
        RewriteRule  ^/(.{1}/.*)$  /wp/$1  [R]
        RewriteRule  ^/(search?.*)$  /wp/$1  [R]
        <Location /wp/>
        ProxyPass http://kiwix:4201/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
        </Location>
</VirtualHost>
</VirtualHost>
</source>
</syntaxhighlight>


In /etc/apache2/sites-available/default, add the following lines:
*Change /etc/apache2/sites-available/default, add the following lines:
<source lang="text">
<syntaxhighlight style="margin-left:2em;" lang="apache">
<Ifmodule mod_alias.c>
<Ifmodule mod_alias.c>
RedirectMatch permanent /(.*)$ http://kiwix/
RedirectMatch permanent /(.*)$ http://kiwix/
</IfModule>
</IfModule>
</source>
</syntaxhighlight>
 
*Create the directory /var/www/kiwix and an empty file /var/www/kiwix/index.html
*Create a symbolic link in /etc/apache2/sites-enabled/ and reload Apache.
 
=== ..using Nginx ===
 
[http://nginx.org Nginx] is faster and less resources consuming than Apache in this scenario. This step is an alternative to using Apache, if you installed it just for kiwix, you might as well remove Apache.
 
* Install nginx: ''sudo apt-get install nginx''
* Choose between one of the two samples below and save as ''/etc/nginx/sites-available/default''


Create the directory /var/www/kiwix and an empty file /var/www/kiwix/index.html
<syntaxhighlight style="margin:0 0 2em 2em;float:left;border-left:1px solid black;" lang="bash">
server_name localhost kiwix;
root /var/www/kiwix;
location /wp {
  rewrite /wp/(.*) /$1 break;
  proxy_pass        http://localhost:4201;
  proxy_set_header  X-Real-IP  $remote_addr;
}
rewrite ^/(.)/(.*)$ /wp/$1/$2 last;
rewrite ^/search(.*)$ /wp/search$1 last;
error_page  404 = /;
</syntaxhighlight>
<syntaxhighlight style="margin:0 0 2em 2em;float:left;border-left:1px solid black;" lang="bash">
#limit_rate      50k;
#limit_rate_after 4k;
limit_conn_zone  $server_name        zone=perserver:1m;
limit_conn_zone  $binary_remote_addr zone=perip:1m;
limit_req_zone  $binary_remote_addr zone=four:1m rate=4r/s;


Create a symbolic link in /etc/apache2/sites-enabled/ and reload Apache.
# Default server configuration, proxying requests to a kiwix-serve instance running on port 4201
#
# - add zim files to a library.xml, see http://www.kiwix.org/wiki/Kiwix-manage
# chown www-data *.zim library.xml
#
# - then start kiwix-serve (uses dropped privileges, like nginx itself):
# sudo -u www-data -g adm bash -c 'kiwix-serve --port=4201 --library library.xml &>/dev/null &'
#
server {
        # comment next three lines if connection or request rate limits are not needed
        limit_conn perserver 80;
        limit_conn perip 2;
        limit_req  zone=four burst=160;


At this moment all the HTTP request should target to http://kiwix/
        listen 80 default_server;
        #listen [::]:80 default_server;
        port_in_redirect off;


== 7 - install kiwix-serve with content ==
        server_name localhost kiwix;
        root /var/www/kiwix;


Compile and install kiwix-serve or install it from a package.
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;


Choose the content (ZIM file) you want to serve and index it with kiwix-index.
        error_page 400 404 =444 /dropconn_444;
        if ($request_method !~ ^(GET|HEAD)$) { return 444; }
        location = /dropconn_444 { return 444; }


Start kiwix-serve on the port 4201. So you should be typing on your client http://kiwix:4201 get the page served by kiwix-serve.
        location = /favicon.ico {
          access_log off;
        }


Add the kiwix-serve to the init.d following [http://www.debian-administration.org/articles/28 this documentation].
        location = /robots.txt {
          access_log off;
          return 200 "User-Agent: *
Allow: /index.html
Disallow: /
";
        }


== 8 - Integrate kiwix-serve and Apache with mod_proxy ==
        location ~ ^/([^/]*_all_|mw|random|search|skin|suggest)(.*)$ {
          # Choose these links as "Home" pages within respective wikis (adjust to your needs)
          rewrite ^(/wikipedia_de_all_nopic_2014-11)/$ $1/A/Würmeiszeit.html break;
          rewrite ^(/rezeptewiki_de_all_2014-06)/$ $1/A/html/L/ä/u/t/Läuterzucker.html break;


Activate mod_proxy with "a2enmod proxy proxy_http rewrite"
          # Skip logging certain uris (each tex formula is a png in zim files..)
          if ($request_uri ~ ^/(mw|random|search|skin|suggest)|.(jpe?g|png)$) {
            access_log off;
          }


Insert in the kiwix vhost file:
          proxy_pass        http://127.0.0.1:4201;
          proxy_set_header  X-Real-IP  $remote_addr;
        }
        rewrite ^/wp14/(.*)$ /wikipedia_de_all_nopic_2014-11/A/$1.html last;
        rewrite ^/wp/$ /_all_ last;


<source lang="text">
        location / {
RewriteEngine On
          # For "Library" link of Kiwix Server to work (adjust HOSTNAME to your.setup.tld)
RewriteRule  ^/(.{1}/.*)/wp/$1 [R]
          valid_referers "~(localhost|kiwix|HOSTNAME|([0-9]+.){3}[0-9]+)(|:[0-9]+)/[^/]*_all_";
RewriteRule  ^/(search?.*)$  /wp/$1  [R]
          if ($invalid_referer != 1) {
            rewrite .* /_all_ last;
          }


<Location /wp/>
          # First attempt to serve request as file, then
ProxyPass http://kiwix:4201/
          # as directory, then fall back to displaying a 404.
SetEnv force-proxy-request-1.0 1
          expires 0s;
SetEnv proxy-nokeepalive 1
          try_files $uri $uri/ =404;
</Location>
        }
</source>
}
</syntaxhighlight><br style="clear:both"/>


Now you should get the kiwix-serve rendered page by typing http://kiwix/wp/
Now you should get the kiwix-serve rendered page by typing http://kiwix/wp/ You should also consider to compress and delay writing to the nginx access.log file for performance reasons. The following entry in ''nginx.conf'' will gzip compress and flush log data in 15 minute intervals only:
<syntaxhighlight style="margin:0 0 2em 2em;float:left" lang="bash">access_log /var/log/nginx/access.log combined gzip=9 flush=15m;</syntaxhighlight><br style="clear:both"/>
If you do not care for repeating entries of success messages use ''access_log off;'' directive as shown above to filter out some access patterns from being logged. For further refinements see [http://nginx.org/en/docs/ nginx docs].


== 9 - Welcome pages ==
== Welcome pages ==


Create your welcome pages in HTML. Here is a stub:
Create your welcome pages in HTML under /var/www/kiwix/index.html - here is a stub:


<source lang="text">
<source lang="html4strict">
<html>
<html>
<head>
<head>
Line 104: Line 194:
<ul>
<ul>
<li><a href="/wp/">Surf on Wikipedia</a></li>
<li><a href="/wp/">Surf on Wikipedia</a></li>
<li><a href="kiwix.tar.bz2">Download Kiwix</a></li>
<li><a href="http://www.kiwix.org/wiki/Software/">Download Kiwix</a></li>
<li><a href="wikipedia.zim">Download Wikipedia</a></li>
<li><a href="http://www.kiwix.org/wiki/Content_in_all_languages">Download Wikipedia</a></li>
</ul>
</ul>
</body>
</body>
Line 112: Line 202:


== Bugs ==
== Bugs ==
== See also ==
* [[Plug solution]]
[[Category:User's Guide]]

Latest revision as of 03:08, 18 February 2016

This page is a HOWTO to create a Kiwix Wifi kiosk, a simple wifi hotspot which allow user to surf on Wikipedia using kiwix-serve and also provide all necessary files to download.

Hardware

Almost all hardware may be able to help to build such a wifi hotspot. We use a small PC based on a x86 and using a USB wifi dongle. To install Debian on the computer, we use an additional USB HD.

OS Installation

Install unetbootin and start it. unetbootin propose you to install a debian unstable netinstall on your USB key, do it. Boot your target computer on the usb key and install Debian choosing the options "Web server" and "SSH server".

Install additional packages

You should now be able to connect to you computer using SSH, you may consequently to all the next steps remotly. Install the following packags : wireless-tools, dnsmasq Check that you wirelss card is correctly recognized.

Configuration network

Add to the /etc/network/interfaces

# wlan
auto wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
wireless-essid KIWIX
wireless-mode ad-hoc

Try to start the interface with: ifconfig wlan0 up

Configuration of DNS & DHCP

Enable the option in /etc/dnsmasq.conf :

  • bogus-priv
  • address = /#/192.168.1.1
  • interface=wlan0
  • dhcp-range=192.168.1.50,192.168.1.150,1h

At this moment you should be able to freely connect to the KIWIX hotspot and your web browser should display for any request the default Apache web page.

Install kiwix-serve with content

Compile and install kiwix-serve or install it from a package.

Choose the content (ZIM file) you want to serve and index it with kiwix-index.

Start kiwix-serve on the port 4201. So you should be typing on your client http://kiwix:4201 get the page served by kiwix-serve.

Add the kiwix-serve to the init.d following this documentation.

Integrate kiwix-serve ..

..using Apache with mod_proxy

  • Activate mod_proxy with "a2enmod proxy proxy_http rewrite"
  • Create a vhost for kiwix in the file /etc/apache2/sites-available/kiwix like the following.
<VirtualHost *:80>
        ServerName kiwix
        DocumentRoot /var/www/kiwix/

        RewriteEngine On
        RewriteRule   ^/(.{1}/.*)$  /wp/$1  [R]
        RewriteRule   ^/(search?.*)$  /wp/$1  [R]

        <Location /wp/>
        ProxyPass http://kiwix:4201/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
        </Location>
</VirtualHost>
  • Change /etc/apache2/sites-available/default, add the following lines:
<Ifmodule mod_alias.c>
	RedirectMatch permanent /(.*)$ http://kiwix/
</IfModule>
  • Create the directory /var/www/kiwix and an empty file /var/www/kiwix/index.html
  • Create a symbolic link in /etc/apache2/sites-enabled/ and reload Apache.

..using Nginx

Nginx is faster and less resources consuming than Apache in this scenario. This step is an alternative to using Apache, if you installed it just for kiwix, you might as well remove Apache.

  • Install nginx: sudo apt-get install nginx
  • Choose between one of the two samples below and save as /etc/nginx/sites-available/default
server_name localhost kiwix;
root /var/www/kiwix;
location /wp {
  rewrite /wp/(.*) /$1 break;
  proxy_pass        http://localhost:4201;
  proxy_set_header  X-Real-IP  $remote_addr;
}
rewrite ^/(.)/(.*)$ /wp/$1/$2 last;
rewrite ^/search(.*)$ /wp/search$1 last;
error_page   404 = /;
#limit_rate       50k;
#limit_rate_after 4k;
limit_conn_zone  $server_name        zone=perserver:1m;
limit_conn_zone  $binary_remote_addr zone=perip:1m;
limit_req_zone   $binary_remote_addr zone=four:1m rate=4r/s;

# Default server configuration, proxying requests to a kiwix-serve instance running on port 4201
#
# - add zim files to a library.xml, see http://www.kiwix.org/wiki/Kiwix-manage
# chown www-data *.zim library.xml
#
# - then start kiwix-serve (uses dropped privileges, like nginx itself):
# sudo -u www-data -g adm bash -c 'kiwix-serve --port=4201 --library library.xml &>/dev/null &'
#
server {
        # comment next three lines if connection or request rate limits are not needed
        limit_conn perserver 80;
        limit_conn perip 2;
        limit_req  zone=four burst=160;

        listen 80 default_server;
        #listen [::]:80 default_server;
        port_in_redirect off;

        server_name localhost kiwix;
        root /var/www/kiwix;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        error_page 400 404 =444 /dropconn_444;
        if ($request_method !~ ^(GET|HEAD)$) { return 444; }
        location = /dropconn_444 { return 444; }

        location = /favicon.ico {
          access_log off;
        }

        location = /robots.txt {
          access_log off;
          return 200 "User-Agent: *
Allow: /index.html
Disallow: /
";
        }

        location ~ ^/([^/]*_all_|mw|random|search|skin|suggest)(.*)$ {
          # Choose these links as "Home" pages within respective wikis (adjust to your needs)
          rewrite ^(/wikipedia_de_all_nopic_2014-11)/$ $1/A/Würmeiszeit.html break;
          rewrite ^(/rezeptewiki_de_all_2014-06)/$ $1/A/html/L/ä/u/t/Läuterzucker.html break;

          # Skip logging certain uris (each tex formula is a png in zim files..)
          if ($request_uri ~ ^/(mw|random|search|skin|suggest)|.(jpe?g|png)$) {
            access_log off;
          }

          proxy_pass        http://127.0.0.1:4201;
          proxy_set_header  X-Real-IP  $remote_addr;
        }
        rewrite ^/wp14/(.*)$ /wikipedia_de_all_nopic_2014-11/A/$1.html last;
        rewrite ^/wp/$ /_all_ last;

        location / {
          # For "Library" link of Kiwix Server to work (adjust HOSTNAME to your.setup.tld)
          valid_referers "~(localhost|kiwix|HOSTNAME|([0-9]+.){3}[0-9]+)(|:[0-9]+)/[^/]*_all_";
          if ($invalid_referer != 1) {
            rewrite .* /_all_ last;
          }

          # First attempt to serve request as file, then
          # as directory, then fall back to displaying a 404.
          expires 0s;
          try_files $uri $uri/ =404;
        }
}


Now you should get the kiwix-serve rendered page by typing http://kiwix/wp/ You should also consider to compress and delay writing to the nginx access.log file for performance reasons. The following entry in nginx.conf will gzip compress and flush log data in 15 minute intervals only:

access_log /var/log/nginx/access.log combined gzip=9 flush=15m;


If you do not care for repeating entries of success messages use access_log off; directive as shown above to filter out some access patterns from being logged. For further refinements see nginx docs.

Welcome pages

Create your welcome pages in HTML under /var/www/kiwix/index.html - here is a stub:

<html>
<head>
  <title>Kiwix Wifi Kiosk</title>
</head>
<body>
<ul>
<li><a href="/wp/">Surf on Wikipedia</a></li>
<li><a href="http://www.kiwix.org/wiki/Software/">Download Kiwix</a></li>
<li><a href="http://www.kiwix.org/wiki/Content_in_all_languages">Download Wikipedia</a></li>
</ul>
</body>
</html>

Bugs

See also