Nginx Installation & Konfiguration: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(15 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 41: | Zeile 41: | ||
listen [::]:80; | listen [::]:80; | ||
server_name zuxer.desanex.de; | server_name zuxer.desanex.de; | ||
− | root /var/www/ | + | root /var/www/zuxerBsp; |
index index.html; | index index.html; | ||
location / { | location / { | ||
Zeile 47: | Zeile 47: | ||
} | } | ||
} | } | ||
− | *Danach einen softlink | + | *Danach einen softlink auf'''etc/nginx/sites-enable/zuxer.desanex.de.conf''' erstellen um die Seite zu aktivieren |
ln -s ../sites-available/zuxer.desanex.de.conf ../sites-enabled/zuxer.desanex.de.conf | ln -s ../sites-available/zuxer.desanex.de.conf ../sites-enabled/zuxer.desanex.de.conf | ||
+ | |||
+ | =Selbstsigniertes Zertifikat erstellen= | ||
+ | |||
+ | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt | ||
+ | *Nun folgt eine Abfrage an Informationen durch den Befehl | ||
+ | Country Name (2 letter code) [AU]:de | ||
+ | State or Province Name (full name) [Some-State]:rheinland-pfalz | ||
+ | Locality Name (eg, city) []:zweibruecken | ||
+ | Organization Name (eg, company) [Internet Widgits Pty Ltd]:tekkit | ||
+ | Organizational Unit Name (eg, section) []:control | ||
+ | Common Name (e.g. server FQDN or YOUR name) []:tekkit.gmbh | ||
+ | Email Address []: | ||
+ | |||
+ | *Erstellen einer Diffie-Hellman group zum vermitteln der Schlüssel | ||
+ | openssl dhparam -out /etc/nginx/dhparam.pem 4096 | ||
+ | |||
+ | =Konfiguration mit SSL in Nginx= | ||
+ | |||
+ | ==Snippet== | ||
+ | *Neue Datei in '''/etc/nginx/snippets/self-signed.conf''' anlegen und das Zertifikat und den Key eintragen | ||
+ | |||
+ | ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; | ||
+ | ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key; | ||
+ | |||
+ | *Eine weitere Datei in '''/etc/nginx/snippets/ssl-params.conf''' um SSL Einstellung einzutragen | ||
+ | ssl_protocols TLSv1.2; | ||
+ | ssl_prefer_server_ciphers on; | ||
+ | ssl_dhparam /etc/nginx/dhparam.pem; | ||
+ | ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384; | ||
+ | ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0 | ||
+ | ssl_session_timeout 10m; | ||
+ | ssl_session_cache shared:SSL:10m; | ||
+ | ssl_session_tickets off; # Requires nginx >= 1.5.9 | ||
+ | ssl_stapling on; # Requires nginx >= 1.3.7 | ||
+ | ssl_stapling_verify on; # Requires nginx => 1.3.7 | ||
+ | resolver 8.8.8.8 8.8.4.4 valid=300s; | ||
+ | resolver_timeout 5s; | ||
+ | # Disable strict transport security for now. You can uncomment the following | ||
+ | # line if you understand the implications. | ||
+ | # add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; | ||
+ | add_header X-Frame-Options DENY; | ||
+ | add_header X-Content-Type-Options nosniff; | ||
+ | add_header X-XSS-Protection "1; mode=block"; | ||
+ | |||
+ | ==Seiten Einstellung== | ||
+ | |||
+ | *Nun werden die Einstelllungen der Seiten bearbeitet '''/etc/nginx/sites-available/zuxer.desanex.de.conf''' | ||
+ | Ändern der Ports zu 443 und trage die Erstellten snippets mit ein <br> | ||
+ | Der zweite abschnitt dient zur Weiterleitung an HTTPS | ||
+ | <pre> | ||
+ | server { | ||
+ | listen 443 ssl; | ||
+ | listen [::]:443 ssl; | ||
+ | include snippets/self-signed.conf; | ||
+ | include snippets/ssl-params.conf; | ||
+ | |||
+ | server_name example.com www.example.com; | ||
+ | |||
+ | root /var/www/example.com/html; | ||
+ | index index.html index.htm index.nginx-debian.html; | ||
+ | |||
+ | . . . | ||
+ | } | ||
+ | server { | ||
+ | listen 80; | ||
+ | listen [::]:80; | ||
+ | |||
+ | server_name zuxer.desanex.de; | ||
+ | |||
+ | return 301 https://$server_name$request_uri; | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | =Firewall= | ||
+ | |||
+ | *Verfügbare Profile | ||
+ | root@poppe:~# ufw app list | ||
+ | Available applications: | ||
+ | Nginx Full | ||
+ | Nginx HTTP | ||
+ | Nginx HTTPS | ||
+ | OpenSSH | ||
+ | *Für den HTTPS Verkehr erlauben wir '''Nginx Full''' und löschen die '''Nginx HTTP''' | ||
+ | root@poppe:~# ufw allow 'Nginx Full' | ||
+ | Rules updated | ||
+ | Rules updated (v6) | ||
+ | root@poppe:~# ufw delete allow 'Nginx HTTP' | ||
+ | <br> | ||
+ | root@poppe:~# ufw status | ||
+ | Status: active | ||
+ | |||
+ | To Action From | ||
+ | -- ------ ---- | ||
+ | OpenSSH ALLOW Anywhere | ||
+ | Nginx Full ALLOW Anywhere | ||
+ | OpenSSH (v6) ALLOW Anywhere (v6) | ||
+ | Nginx Full (v6) ALLOW Anywhere (v6) | ||
+ | |||
+ | =Nginx neustarten= | ||
+ | root@poppe:~# systemctl restart nginx |
Version vom 24. März 2020, 11:37 Uhr
Installation
- sudo apt-get install nginx
localhost
HTML Seite
- Die Standard Seite befindet sich unter /var/www/html/
- Erstelle einen neuen Ordner unter www
root@poppe:/# mkdir /var/www/zuxerBsp root@poppe:/# cd /var/www/zuxerBsp/ root@poppe:/var/www/zuxerBsp# vi index.html
- Ein Standard Beispiel für eine html Seite wäre
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Hallo, Welt!</title> </head> <h1>Hallo Welt</h1> <body> Wir haben gerade erfolgreich unseren nginx Server aufgestellt! </body> </html>
Kofiguration
- Zuerst wird die Konfigurationsdatei erstellt und anschließend bearbeitet
root@poppe:/etc/nginx/sites-available# touch zuxer.desanex.de.conf root@poppe:/etc/nginx/sites-available# vi zuxer.desanex.de.conf
- /etc/nginx/sites-available/zuxer.desanex.de.conf
server { listen 80; listen [::]:80; server_name zuxer.desanex.de; root /var/www/zuxerBsp; index index.html; location / { try_files $uri $uri/ =404; } }
- Danach einen softlink aufetc/nginx/sites-enable/zuxer.desanex.de.conf erstellen um die Seite zu aktivieren
ln -s ../sites-available/zuxer.desanex.de.conf ../sites-enabled/zuxer.desanex.de.conf
Selbstsigniertes Zertifikat erstellen
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
- Nun folgt eine Abfrage an Informationen durch den Befehl
Country Name (2 letter code) [AU]:de State or Province Name (full name) [Some-State]:rheinland-pfalz Locality Name (eg, city) []:zweibruecken Organization Name (eg, company) [Internet Widgits Pty Ltd]:tekkit Organizational Unit Name (eg, section) []:control Common Name (e.g. server FQDN or YOUR name) []:tekkit.gmbh Email Address []:
- Erstellen einer Diffie-Hellman group zum vermitteln der Schlüssel
openssl dhparam -out /etc/nginx/dhparam.pem 4096
Konfiguration mit SSL in Nginx
Snippet
- Neue Datei in /etc/nginx/snippets/self-signed.conf anlegen und das Zertifikat und den Key eintragen
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
- Eine weitere Datei in /etc/nginx/snippets/ssl-params.conf um SSL Einstellung einzutragen
ssl_protocols TLSv1.2; ssl_prefer_server_ciphers on; ssl_dhparam /etc/nginx/dhparam.pem; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384; ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0 ssl_session_timeout 10m; ssl_session_cache shared:SSL:10m; ssl_session_tickets off; # Requires nginx >= 1.5.9 ssl_stapling on; # Requires nginx >= 1.3.7 ssl_stapling_verify on; # Requires nginx => 1.3.7 resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 5s; # Disable strict transport security for now. You can uncomment the following # line if you understand the implications. # add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block";
Seiten Einstellung
- Nun werden die Einstelllungen der Seiten bearbeitet /etc/nginx/sites-available/zuxer.desanex.de.conf
Ändern der Ports zu 443 und trage die Erstellten snippets mit ein
Der zweite abschnitt dient zur Weiterleitung an HTTPS
server { listen 443 ssl; listen [::]:443 ssl; include snippets/self-signed.conf; include snippets/ssl-params.conf; server_name example.com www.example.com; root /var/www/example.com/html; index index.html index.htm index.nginx-debian.html; . . . } server { listen 80; listen [::]:80; server_name zuxer.desanex.de; return 301 https://$server_name$request_uri; }
Firewall
- Verfügbare Profile
root@poppe:~# ufw app list Available applications:
Nginx Full Nginx HTTP Nginx HTTPS OpenSSH
- Für den HTTPS Verkehr erlauben wir Nginx Full und löschen die Nginx HTTP
root@poppe:~# ufw allow 'Nginx Full' Rules updated Rules updated (v6) root@poppe:~# ufw delete allow 'Nginx HTTP'
root@poppe:~# ufw status Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx Full ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx Full (v6) ALLOW Anywhere (v6)
Nginx neustarten
root@poppe:~# systemctl restart nginx