Apache kompilieren mit http/2 support
GKO
Ziel
Es soll ein Web-Server auf Basis von http://nginx.org/ mit PHP5, MySQL und HTTP/2 Support eingerichtet werden. Ein gemeinsamer Betrieb mit Apache2 ist möglich, da man bei NGINX den Port von 80 sehr leicht auf einen anderen Port ändern kann. So könnte man z.B. alle Seiten, die besonders von HTTP/2 profitieren, von dem NGINX Server hosten lassen. Ferner biete NGINX ein paar Features im Bereich Mediastreaming an, die der Apache2 so in der Form nicht von Haus aus mitbringt.
Grundvoraussetzungen
Ubuntu Server 14.04 LTS Datenbankserver (optional)
Damit die möglichst aktuelle Version von NGINX installiert wird, muss das Repo von NGINX noch hinzugefügt werden.
sudo add-apt-repository ppa:nginx/stable
Damit wird Stand 16.02.2016 aber "nur" Version 1.8.1 installiert, das nur den Vorgänger von HTTP/2 namens SPDY beeinhaltet. HTTP/2 bekommt man aktuell nur wenn man das Developer Repo einbindet, welches aber dann noch Fehler enthalten könnte. Installiert wird dann Version 1.9.10
sudo add-apt-repository ppa:nginx/developer
Muss man sich halt vorher überlegen, ob das sinnvoll ist oder nicht. Aber da der Server nur für eine handvoll Menschen seinen Dienst verrichtet, nehme ich mal die Developer Edition.
Die Versionsnummer kann über das Kommando
nginx -v
ermittelt werden.
Schritt für Schritt-Anleitung
Anpassen der Konfiguration
Die Hauptkonfigurationsdatei liegt in /etc/nginx/nginx.conf. Dort ist eine logik hinterlegt, die alle unter /etc/nginx/sites-enabled/ abgelegten Dateien included. Daher sollten alle Einstellungen unter
/etc/nginx/sites-enabled/default
durchgeführt werden.
Selbstsigniertes SSL-Zertifikat erzeugen
Kopiert von https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-nginx-for-ubuntu-14-04
sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
oder mit einem Online Zertifikat Generator
Zertifikat in die Configdatei einbinden
innerhalb des Server {} blocks diese Zeilen hinzufügen. Am besten direkt nach dem listen parameter
listen 443 ssl http2;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
Darüber hinaus ist auch ein Blick auf den Mozilla SSL Configuration Generator empfehlenswert.
Fertige und funktionierende Konfiguration
nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 2;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
#### Enable PHP requests
### https://thomas-leister.de/open-source/linux/ubuntu/nginx-php-fpm-installieren-ubuntu-server/
upstream php {
server unix:/var/run/php5-fpm.sock;
}
}
sites-enabled/default
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
charset UTF-8;
# Alle Anfragen auf HTTPS weiterleiten.
return 301 https://$host$request_uri;
}
server {
# SSL configuration
#
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
gzip off;
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/htdocs;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~* \.php$ {
include fastcgi.conf;
fastcgi_pass php;
fastcgi_index index.php;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
NGINX fit für PHP machen
NGINX nutzt die CGI Schnittstelle um PHP Scripte an den PHP Parser zu übergeben. Dazu wird dann das passende Gegenstück benötigt das mit
sudo apt-get install php5-curl php5-gd php5-fpm
installiert wird. Dadurch wird ein Service installiert der auf Port 9000 lauscht.
SQLite untersützung nachinstallieren (optional)
sudo apt-get install sqlite
oder
sudo apt-get install sqlite3 php5-sqlite
JPA
Grundvoraussetzungen
Als Grundsystem kommt Ubuntu 15.04 zum Einsatz.
Schritt für Schritt-Anleitung
1. Installieren der Software-Voraussetzungen
aptitude install gcc make libpcre3-dev
apt-get install libaprutil1-dev libapr1-dev dh-make build-essential
3. Mit cd in das Verzeichnis wechseln
cd ~/
4. Download http://httpd.apache.org/download.cgi aktuelle apache2 version
wget http://mirrors.ae-online.de/apache//httpd/httpd-2.4.18.tar.gz
5. Extrahieren der tar datei
tar xpzf httpd-2.4.18.tar.gz && rm httpd-2.4.18.tar.gz
6. Umbenennen des Verzeichnisses
mv httpd-2.4.18 http
7. Wechseln des Verzeichnisses nach srclib
cd http/srclib
11. Wechseln des Verzeichnisses
cd ~/http
12. nghttp2 Vor der kompilierung muss die nghttp2lib kompiliert und installiert werden.
# Get build requirements
# Some of these are used for the Python bindings
# this package also installs
sudo apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config \
zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev \
libjemalloc-dev cython python3-dev python-setuptools
# Build nghttp2 from source
git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2
autoreconf -i
automake autoconf
./configure
make
sudo make install
Quelle: https://serversforhackers.com/video/curl-with-http2-support
Apache2 kompilieren
./configure \
--with-pcre=/usr \
--enable-mpms-shared=all \
--enable-unixd=static \
--enable-layout=Debian --enable-so \
--with-program-name=apache2 \
--with-ldap=yes --with-ldap-include=/usr/include \
--with-ldap-lib=/usr/lib \
--with-suexec-caller=www-data \
--with-suexec-bin=/usr/lib/apache2/suexec \
--with-suexec-docroot=/var/www \
--with-suexec-userdir=public_html \
--with-suexec-logfile=/var/log/apache2/suexec.log \
--with-suexec-uidmin=100 \
--enable-suexec=shared \
--enable-log-config=static --enable-logio=static \
--enable-version=static \
--with-apr=/usr/bin/apr-1-config \
--with-apr-util=/usr/bin/apu-1-config \
--with-pcre=yes \
--enable-pie \
--enable-authn-alias=shared --enable-authnz-ldap=shared \
--enable-disk-cache=shared --enable-cache=shared \
--enable-mem-cache=shared --enable-file-cache=shared \
--enable-cern-meta=shared --enable-dumpio=shared --enable-ext-filter=shared \
--enable-charset-lite=shared --enable-cgi=shared \
--enable-dav-lock=shared --enable-log-forensic=shared \
--enable-ldap=shared --enable-proxy=shared \
--enable-proxy-connect=shared --enable-proxy-ftp=shared \
--enable-proxy-http=shared --enable-proxy-ajp=shared \
--enable-proxy-scgi=shared \
--enable-proxy-balancer=shared --enable-ssl=shared \
--enable-authn-dbm=shared --enable-authn-anon=shared \
--enable-authn-dbd=shared --enable-authn-file=shared \
--enable-authn-default=shared --enable-authz-host=shared \
--enable-authz-groupfile=shared --enable-authz-user=shared \
--enable-authz-dbm=shared --enable-authz-owner=shared \
--enable-authnz-ldap=shared --enable-authz-default=shared \
--enable-auth-basic=shared --enable-auth-digest=shared \
--enable-dbd=shared --enable-deflate=shared \
--enable-include=shared --enable-filter=shared \
--enable-env=shared --enable-mime-magic=shared \
--enable-expires=shared --enable-headers=shared \
--enable-ident=shared --enable-usertrack=shared \
--enable-unique-id=shared --enable-setenvif=shared \
--enable-status=shared \
--enable-autoindex=shared --enable-asis=shared \
--enable-info=shared --enable-cgid=shared \
--enable-dav=shared --enable-dav-fs=shared \
--enable-vhost-alias=shared --enable-negotiation=shared \
--enable-dir=shared --enable-imagemap=shared \
--enable-actions=shared --enable-speling=shared \
--enable-userdir=shared --enable-alias=shared \
--enable-rewrite=shared --enable-mime=shared \
--enable-http2 \
--enable-substitute=shared --enable-reqtimeout=shared;
make
make install
===Konfiguration für Apache2 fit machen===
Folgende Zeile suchen und auskommentieren - sprich das # Zeichen entfernen
<source lang="bash">
LoadModule http2_module modules/mod_http2.so
No Comments