Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| server:nginx [2019/02/26 12:25] – [Reverse-Proxy-Config] st | server:nginx [2022/03/01 22:31] (aktuell) – [Links] st | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== nginx ====== | ||
| + | nginx ist ein HTTP server und IMAP/ | ||
| + | |||
| + | ===== Links ===== | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | |||
| + | |||
| + | ===== VHosts mit SNI ===== | ||
| + | |||
| + | **DefaultServer**: | ||
| + | <code bash> | ||
| + | server { | ||
| + | listen 443 ssl default_server; | ||
| + | listen [::]:443 ssl default_server; | ||
| + | |||
| + | server_name example.org; | ||
| + | |||
| + | server_tokens off; | ||
| + | # required: path to certificate and private key | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | |||
| + | # required for OCSP stapling, if any of your vhosts don't have this line, you have to inactivate OCSP stapling in ssl.conf | ||
| + | ssl_trusted_certificate / | ||
| + | |||
| + | # Include global SSL settings | ||
| + | include / | ||
| + | root / | ||
| + | index index.html index.htm; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | **Server example.com** | ||
| + | <code bash> | ||
| + | server { | ||
| + | listen 443 ssl default_server; | ||
| + | listen [::]:443 ssl default_server; | ||
| + | |||
| + | server_tokens off; | ||
| + | # required: path to certificate and private key | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | |||
| + | # required for OCSP stapling, if any of your vhosts don't have this line, you have to inactivate OCSP stapling in ssl.conf | ||
| + | ssl_trusted_certificate / | ||
| + | |||
| + | # Include global SSL settings | ||
| + | include / | ||
| + | |||
| + | root / | ||
| + | index index.html index.htm; | ||
| + | |||
| + | location / { | ||
| + | proxy_pass | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | **Die Allgemeinen Einstellungen**: | ||
| + | <code bash> | ||
| + | # Basically the nginx configuration I use at konklone.com. | ||
| + | # I check it using https:// | ||
| + | # | ||
| + | # To provide feedback, please tweet at @konklone or email eric@konklone.com. | ||
| + | # Comments on gists don't notify the author. | ||
| + | # | ||
| + | # Thanks to WubTheCaptain (https:// | ||
| + | # Thanks to Ilya Grigorik (https:// | ||
| + | |||
| + | # HTTP Strict Transport Security: tells browsers to require https:// without first checking | ||
| + | # the http:// version for a redirect. Warning: it is difficult to change your mind. | ||
| + | # | ||
| + | # max-age: length of requirement in seconds (31536000 = 1 year) | ||
| + | # includeSubdomains: | ||
| + | # preload: indicates you want browsers to ship with HSTS preloaded for your domain. | ||
| + | # | ||
| + | # Submit your domain for preloading in browsers at: https:// | ||
| + | #add_header Strict-Transport-Security ' | ||
| + | |||
| + | # If you won' | ||
| + | add_header Strict-Transport-Security ' | ||
| + | |||
| + | # Prefer certain ciphersuites, | ||
| + | # | ||
| + | # Forces forward secrecy in all browsers and clients that can use TLS, | ||
| + | # but with a small exception (DES-CBC3-SHA) for IE8/XP users. | ||
| + | # | ||
| + | # Reference client: https:// | ||
| + | ssl_prefer_server_ciphers on; | ||
| + | ssl_ciphers ' | ||
| + | |||
| + | # Now let's really get fancy, and pre-generate a 2048 bit random parameter | ||
| + | # for DH elliptic curves. If not created and specified, default is only 1024 bits. | ||
| + | # | ||
| + | # Generated by OpenSSL with the following command: | ||
| + | # | ||
| + | ssl_dhparam / | ||
| + | |||
| + | # Cut out the old, broken, insecure SSLv2 and SSLv3 entirely. | ||
| + | ssl_protocols TLSv1.2 TLSv1.1 TLSv1; | ||
| + | |||
| + | |||
| + | # optional: turn on session resumption, using a 10 min cache shared across nginx processes | ||
| + | # as recommended by http:// | ||
| + | ssl_session_cache | ||
| + | ssl_session_timeout 10m; | ||
| + | keepalive_timeout | ||
| + | |||
| + | # Buffer size of 1400 bytes fits in one MTU. | ||
| + | # nginx 1.5.9+ ONLY | ||
| + | ssl_buffer_size 1400; | ||
| + | |||
| + | # OCSP stapling - means nginx will poll the CA for signed OCSP responses, | ||
| + | # and send them to clients so clients don't make their own OCSP calls. | ||
| + | # https:// | ||
| + | # | ||
| + | # while the ssl_certificate above may omit the root cert if the CA is trusted, | ||
| + | # ssl_trusted_certificate below must point to a chain of **all** certs | ||
| + | # in the trust path - (your cert, intermediary certs, root cert) | ||
| + | # | ||
| + | # 8.8.8.8 and 8.8.4.4 below are Google' | ||
| + | # nginx will use them to talk to the CA. | ||
| + | ssl_stapling on; | ||
| + | ssl_stapling_verify on; | ||
| + | resolver 8.8.8.8 8.8.4.4 valid=86400; | ||
| + | resolver_timeout 10; | ||
| + | </ | ||
| + | |||
| + | ===== Reverse-Proxy-Config ===== | ||
| + | |||
| + | Bespiel: | ||
| + | * $FQDN worauf sollen sich Clients verbinden können? z.B. server.domain.tld | ||
| + | * $SSL_PORT Welcher Port soll nach Außen geöffent werden? 443 ist standard | ||
| + | * $TARGET_FQDN wohin sollen die Clients (transparent) umgeleitet werden: z.B localhost | ||
| + | * $TARGET_PORT auf welchen Port sollen die Clients (transparent) umgeleitet werden: z.B. 8080 | ||
| + | * https:// | ||
| + | |||
| + | :!: Die Datei ssl_certificate -> / | ||
| + | |||
| + | **Konfiguration** (liegt in sites-available mit Symlink auf sites-enabled: | ||
| + | < | ||
| + | server{ | ||
| + | listen 80; | ||
| + | listen [::]:80; | ||
| + | server_name $FQDN; | ||
| + | server_tokens off; | ||
| + | return 301 https:// | ||
| + | } | ||
| + | |||
| + | server{ | ||
| + | listen $SSL_PORT ssl; | ||
| + | listen [:: | ||
| + | server_name $FQDN; | ||
| + | |||
| + | server_tokens off; | ||
| + | ssl_certificate | ||
| + | ssl_certificate_key / | ||
| + | |||
| + | ssl on; | ||
| + | # source: https:// | ||
| + | ssl_session_cache | ||
| + | # TLSv1.3 Requires nginx >= 1.13.0 AND openssl 1.1.1 (the updated Ubuntu 18.04 has openssl 1.1.1 ): | ||
| + | # ssl_protocols TLSv1.2 TLSv1.3; | ||
| + | ssl_protocols TLSv1.2; | ||
| + | ssl_prefer_server_ciphers on; | ||
| + | # openssl dhparam -out / | ||
| + | ssl_dhparam / | ||
| + | ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512: | ||
| + | ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0 | ||
| + | ssl_session_timeout | ||
| + | ssl_session_cache shared: | ||
| + | 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 $DNS-IP-1 $DNS-IP-2 valid=300s; | ||
| + | # | ||
| + | # HSTS on: | ||
| + | add_header Strict-Transport-Security " | ||
| + | #add_header X-Frame-Options DENY; | ||
| + | #add_header X-Content-Type-Options nosniff; | ||
| + | #add_header X-XSS-Protection "1; mode=block"; | ||
| + | |||
| + | access_log / | ||
| + | error_log / | ||
| + | |||
| + | location / { | ||
| + | |||
| + | # pass Host-header (from client) through: | ||
| + | proxy_set_header | ||
| + | # pass information about this proxy: | ||
| + | proxy_set_header | ||
| + | proxy_set_header | ||
| + | proxy_set_header | ||
| + | |||
| + | # Fix the "It appears that your reverse proxy set up is broken" | ||
| + | proxy_pass | ||
| + | proxy_read_timeout | ||
| + | # verify SSL-Cert on proxy_pass target: | ||
| + | # proxy_ssl_verify on | ||
| + | # proxy_redirect | ||
| + | |||
| + | # websockets? | ||
| + | # proxy_http_version 1.1; | ||
| + | # proxy_set_header Upgrade $http_upgrade; | ||
| + | # proxy_set_header Connection $http_connection; | ||
| + | |||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Quellen: | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | ===== IPv6 ===== | ||
| + | |||
| + | nginx braucht in jedem virtual Host die entsprechenden listen-Direktiven: | ||
| + | |||
| + | < | ||
| + | # v4: -> 0.0.0.0:80 | ||
| + | listen 80; | ||
| + | # v6: -> :::443 | ||
| + | listen [::]:80; | ||
| + | </ | ||
| + | |||
| + | SSL/TLS: | ||
| + | < | ||
| + | # v4: | ||
| + | listen 443 ssl; | ||
| + | # v6: | ||
| + | listen [::]:443 ssl; | ||
| + | </ | ||
| + | |||
| + | einzeilig geht es mit der option ipv6only, bei " | ||
| + | < | ||