Übersicht
- Teil 1: Vorwort
- Teil 2: Installation und Konfiguration
- Teil 3: PHP
- Teil 4: Einen Tomcat anbinden
- Teil 5: Basic Authentication
Installation
Um eine aktuelle Version (1.0.6) auch unter Debian zu bekommen, kann man einfach das dotdeb Repository in die sources.list aufnehmen:
dotdeb.org bietet ein umfangreiches Repository um Debian Systeme in perfekte LAMP Server zu verwandeln. Hier ist nicht nur die aktuelle Version von PHP 5.3 mit dem FPM, den ich später noch brauchen werde, sondern auch die aktuelle Version des nginx zu finden. Außerdem ist die Default-Konfiguration des Nginx aus dem dotdeb Repo etwas sauberer als die aus dem offiziellen Debian Nginx Repo …
# vim /etc/apt/sources.list
deb http://packages.dotdeb.org stable all deb-src http://packages.dotdeb.org stable all
Danach kurz die Paketliste aktualisieren und den nginx installieren:
# apt-get update # apt-get install nginx
Basis Konfiguration
Was mir im Konfigurationsverzeichnis des Nginx direkt auffällt sind die beiden Verzeichnisse “sites-avilable” und “sites-enabled”, welche man ja bereits vom apache kennt.
In der nginx.conf ändere ich folgende Parameter:
- user www-data www-data;
- index index.php index.htm index.html;
In den http-Block füge ich außerdem noch einige gzip Parameter ein:
gzip on;
gzip_comp_level 9;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg;
gzip_http_version 1.1;
gzip_min_length 1000;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6] \.";
gzip_vary on;
Zusätzlich benötigen wir zwei Include Statements. Ersteres sollte bereits in der nginx.conf enthalten sein. Letzteres benötigen wir für die VHosts:
include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*;
Virtuelle Hosts konfigurieren
Im sites-aviable Verzeichnis benenne ich die Datei “default” in “itws.de” um und füge folgenden Inhalt ein:
server {
server_name itws.de www.itws.de;
root /var/www/itws.de/www;
# redirection to blog.itws.de
rewrite ^(.*) http://blog.itws.de$1 permanent;
}
server {
server_name blog.itws.de;
root /var/www/itws.de/blog;
location / {
try_files $uri $uri/ /index.php /index.html;
}
location ~ /\.ht {
deny all;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
root /var/www;
}
}
server {
server_name ci.itws.de;
root /var/www/itws.de/ci;
location / {
try_files $uri $uri/ /index.php /index.html;
}
location ~ /\.ht {
deny all;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
root /var/www;
}
}
Im Wiki gibts mehr Beispiele, Parameter und Dokumentation.
Danach gibts noch eine Datei yaana.de mit ähnlichem Inhalt.
Im Anschluss daran müssen beide Konfigurationen aktiviert werden:
# ln -s /etc/nginx/sites-available/itws.de /etc/nginx/sites-enabled/itws.de # ln -s /etc/nginx/sites-available/yaana.de /etc/nginx/sites-enabled/yaana.de
Diese Konfiguration kann ich mit 2-3 statischen Hallo-Welt-Dateien schonmal testen.
Funktioniert einwandfrei.
Jetzt möchte ich aber nicht jedes Mal diese ganzen location-Blöcke in jedem VHost haben. Deswegen lege ich mir eine Include Datei hierfür an:
# vim /etc/nginx/defaults.inc
Diese erhält folgenden Inhalt:
location / {
try_files $uri $uri/ /index.php /index.html;
}
location ~ /\. {#
access_log off;
log_not_found off;
deny all;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
}
location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ {
deny all;
}
Nun ändere ich meine VHost Konfigurationen entsprechend ab:
server {
server_name itws.de www.itws.de;
root /var/www/itws.de/www;
# redirection to blog.itws.de
rewrite ^(.*) http://blog.itws.de$1 permanent;
}
server {
server_name blog.itws.de;
root /var/www/itws.de/blog;
Include defaults.inc;
}
server {
server_name ci.itws.de;
root /var/www/itws.de/ci;
Include defaults.inc;
}
Perfekt! Weniger Konfiguration als im Apache, aber mehr Performance


Debian: Von Apache zu Nginx – Teil 1: Vorwort | ITWS Developer Blog says:
[...] Kommentare Debian: Von Apache zu Nginx – Teil 2: Installation und Konfiguration | ITWS Developer Blog bei Debian: Von Apache zu Nginx – Teil 3: PHPDebian: Von Apache zu Nginx – Teil 3: PHP [...]
Debian: Von Apache zu Nginx – Teil 3: PHP | ITWS Developer Blog says:
[...] Kommentare Debian: Von Apache zu Nginx – Teil 1: Vorwort | ITWS Developer Blog bei Debian: Von Apache zu Nginx – Teil 2: Installation und KonfigurationDebian: Von Apache zu Nginx – Teil 2: Installation und Konfiguration | ITWS Developer Blog bei [...]
Debian: Von Apache zu Nginx – Teil 4: Einen Tomcat anbinden | ITWS Developer Blog says:
[...] Basic Authentication | ITWS Developer Blog bei Debian: Von Apache zu Nginx – Teil 1: VorwortDebian: Von Apache zu Nginx – Teil 2: Installation und Konfiguration | ITWS Developer Blog bei Debian: Von Apache zu Nginx – Teil 4: Einen Tomcat anbindenDebian: Von Apache zu Nginx [...]