nginx für Raspberry kompilieren
Gestestet unter Debian Stretch und Debian Jessie
Der Webserver nginx ist auch in vielen Repos direkt enthalten. Wenn man jedoch die aktuelle Version mit allen plugins haben möchte, muss man selber ran. Mit dieser Setup ist auch die neue http/2 Unterstützung gewährleistet. Allerdings muss dazu ein SSL-Zertifikat vorliegen, da http/2 nur via SSL funktioniert.
Das Kompilieren auf dem Raspberry kann 20 Minuten oder länger dauern. Dank des schmalbrüstigen SoC
Diese Script erledigt viele Dinge, die man dazu benötigt:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!/usr/bin/env bash set -x # names of latest versions of each package export VERSION_PCRE=pcre-8.42 export VERSION_OPENSSL=openssl-1.1.0h export VERSION_NGINX=nginx-1.13.11 export VERSION_ZLIB=zlib-1.2.11 export VERSION_MODULE_ECHO=0.60 # URLs to the source directories export SOURCE_OPENSSL=https: //www .openssl.org /source/ export SOURCE_PCRE= ftp : //ftp .csx.cam.ac.uk /pub/software/programming/pcre/ export SOURCE_NGINX=http: //nginx .org /download/ export SOURCE_ZLIB=http: //www .zlib.net/ export SOURCE_MODULE_ECHO=https: //codeload .github.com /openresty/echo-nginx-module/tar .gz /v $VERSION_MODULE_ECHO # clean out any files from previous runs of this script export BPATH=$( pwd ) /build #rm -rf $BPATH mkdir -p $BPATH # ensure that we have the required software to compile our own nginx if [ ! -f ~ /updatesdone ]; then sudo apt-get update sudo apt-get -y install curl wget build-essential touch ~ /updatesdone chmod 666 ~ /updatesdone fi # grab the source files [ ! -f $BPATH/$VERSION_PCRE. tar .gz ] && wget -P $BPATH $SOURCE_PCRE$VERSION_PCRE. tar .gz [ ! -f $BPATH/$VERSION_OPENSSL. tar .gz ] && wget -P $BPATH $SOURCE_OPENSSL$VERSION_OPENSSL. tar .gz --no-check-certificate [ ! -f $BPATH/$VERSION_NGINX. tar .gz ] && wget -P $BPATH $SOURCE_NGINX$VERSION_NGINX. tar .gz [ ! -f $BPATH/$VERSION_ZLIB. tar .gz ] && wget -P $BPATH $SOURCE_ZLIB$VERSION_ZLIB. tar .gz [ ! -f $BPATH /v $VERSION_MODULE_ECHO. tar .gz ] && wget -O v $VERSION_MODULE_ECHO. tar .gz -P $BPATH $SOURCE_MODULE_ECHO # expand the source files cd $BPATH tar xzf $VERSION_NGINX. tar .gz tar xzf $VERSION_OPENSSL. tar .gz tar xzf $VERSION_PCRE. tar .gz tar xzf $VERSION_ZLIB. tar .gz tar xzf $BPATH /v0 .60. tar .gz cd ../ # rename the existing /etc/nginx directory so it's saved as a back-up mv /etc/nginx /etc/nginx-bk # build nginx, with various modules included/excluded cd $BPATH/$VERSION_NGINX mkdir -p $BPATH /nginx . /configure --sbin-path= /usr/sbin/nginx \ --conf-path= /etc/nginx/nginx .conf \ --pid-path= /var/run/nginx .pid \ --error-log-path= /var/log/nginx/error .log \ --http-log-path= /var/log/nginx/access .log \ --with-pcre=$BPATH/$VERSION_PCRE \ --with-http_ssl_module \ --with- file -aio \ --with-zlib=$BPATH/$VERSION_ZLIB \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-http_v2_module \ --with-http_sub_module \ --with-select_module \ --with-poll_module \ --without-mail_pop3_module \ --without-mail_smtp_module \ --without-mail_imap_module \ --with-http_dav_module \ --with-openssl=$BPATH/$VERSION_OPENSSL make && make install # rename the compiled /etc/nginx directory so its accessible as a reference to the new nginx defaults #mv /etc/nginx /etc/nginx-default # now restore the /etc/nginx-bk to /etc/nginx so the old settings are kept mv /etc/nginx-bk /etc/nginx echo "All done." ; echo "This build has not edited your existing /etc/nginx directory." ; echo "If things aren't working now you may need to refer to the" ; echo "configuration files the new nginx ships with as defaults," ; echo "which are available at /etc/nginx-default" ; |
Default Konfig kopieren
in /etc/nginx-default lioegen die Standardeinstellungen, die man sich kopieren sollte. Wenn man jedoch schon eine config hat, kann dieser Schritt übersprungen werden.
sudo cp -r /etc/nginx- default /etc/nginx |
Ferner hat es sich bewährt, so wie bei Apache zwei Verzeichnisse anzulegen.
- sites-available
- sites-enabled
So ist es möglich einzelne Webseiten über symbolische Links ein- und auszuschalten.
sudo mkdir /etc/nginx/sites-available /etc/nginx/sites-enabled |
Dann muss jedoch auch in der nginx.conf noch folgender Eintrag im http Block ergänzt werden:
include /etc/nginx/sites-enabled/*; |
Standardpfad zu dem HTML-Verzeichnis
In der nginx.conf ist als rootdir "html" angegeben. Das ist ein relativer Pfad, der vollständig /usr/local/nginx/html/
heisst.
Autostart über systemd
TODO
No Comments