server:nginx

nginx

nginx ist ein HTTP server und IMAP/POP3/SMTP-Proxy server.

DefaultServer:

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			/opt/keys/example.org/example.org.unified.crt;
  ssl_certificate_key		/opt/keys/example.org/example.org.decrypted.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		/opt/keys/example.org/example.org.unified+root.crt;
 
  # Include global SSL settings
  include /etc/nginx/ssl.conf;
  root   /usr/share/nginx/html;
  index  index.html index.htm;
}

Server example.com

server {
  listen 443 ssl default_server;
  listen [::]:443 ssl default_server;
 
  server_tokens off;
  # required: path to certificate and private key
  ssl_certificate			/opt/keys/example.com/example.com.unified.crt;
  ssl_certificate_key		/opt/keys/example.com/example.com.decrypted.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		/opt/keys/example.com/example.com.unified+root.crt;
 
  # Include global SSL settings
  include /etc/nginx/ssl.conf;
 
  root /usr/share/nginx/html;
  index index.html index.htm;
 
  location / {
    proxy_pass  http://upstream;
  }
}

Die Allgemeinen Einstellungen:

# Basically the nginx configuration I use at konklone.com. 
# I check it using https://www.ssllabs.com/ssltest/analyze.html?d=konklone.com
#
# To provide feedback, please tweet at @konklone or email eric@konklone.com.
# Comments on gists don't notify the author. 
# 
# Thanks to WubTheCaptain (https://wubthecaptain.eu) for his help and ciphersuites.
# Thanks to Ilya Grigorik (https://www.igvita.com) for constant inspiration.
 
# 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: force SSL for *ALL* subdomains (remove if this is not what you want)
#    preload: indicates you want browsers to ship with HSTS preloaded for your domain.
#
#    Submit your domain for preloading in browsers at: https://hstspreload.appspot.com
#add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';
 
# If you won't/can't turn on HTTPS for *all* subdomains, use this simpler version:
add_header Strict-Transport-Security 'max-age=31536000';
 
# Prefer certain ciphersuites, to enforce Forward Secrecy and avoid known vulnerabilities.
#
# 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://www.ssllabs.com/ssltest/analyze.html
ssl_prefer_server_ciphers on;
ssl_ciphers 'kEECDH+ECDSA+AES128 kEECDH+ECDSA+AES256 kEECDH+AES128 kEECDH+AES256 kEDH+AES128 kEDH+AES256 DES-CBC3-SHA +SHA !aNULL !eNULL !LOW !MD5 !EXP !DSS !PSK !SRP !kECDH !CAMELLIA !RC4 !SEED';
 
# 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:
#   openssl dhparam -outform pem -out dhparam2048.pem 2048
ssl_dhparam /path/to/dhparam2048.pem;
 
# 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://nginx.org/en/docs/http/configuring_https_servers.html
ssl_session_cache   shared:SSL:10m;
ssl_session_timeout 10m;
keepalive_timeout   70;
 
# 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://en.wikipedia.org/wiki/OCSP_stapling
#
# 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's public IPv4 DNS servers.
# 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;

Bespiel:

:!: Die Datei ssl_certificate → /root/$FQDN.crt enthält sowohl das Serverzertifikat als auch die komplette Chain/Intermediates die zur Verfolgung bis hin zum Stammzertifikat nötig sind.

Konfiguration (liegt in sites-available mit Symlink auf sites-enabled:

ln -s /etc/nginx/sites-available/FQDN.conf /etc/nginx/sites-enabled/
server{
  listen 80;
  listen [::]:80;
  server_name $FQDN;
  server_tokens off;
  return 301 https://$FQDN[:$SSL_PORT]$request_uri;
}

server{
  listen $SSL_PORT ssl;
  listen [::]:$SSL_PORT ssl;
  server_name $FQDN;

  server_tokens off;
  ssl_certificate     /root/$FQDN.crt;
  ssl_certificate_key /root/$FQDN.key;

  ssl on;
  # source: https://cipherli.st/
  ssl_session_cache  builtin:1000  shared:SSL:10m;
  # 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 /etc/nginx/dhparam.pem 2048 :
  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 $DNS-IP-1 $DNS-IP-2 valid=300s;
  #resolver_timeout 5s; 
  # HSTS on:
  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";

  access_log /var/log/nginx/$FQDN.access.log;
  error_log /var/log/nginx/$FQDN.error.log;

  location / {

    # pass Host-header (from client) through:
    proxy_set_header    Host $host;
    # pass information about this proxy:
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto $scheme;

    # Fix the "It appears that your reverse proxy set up is broken" error.
    proxy_pass          http://$TARGET_FQDN:$TARGET_PORT;
    proxy_read_timeout  30;
    # verify SSL-Cert on proxy_pass target:
    # proxy_ssl_verify on
    # proxy_redirect      http://$TARGET_FQDN:$TARGET_PORT http://$FQDN:$TARGET_PORT;

    # websockets?
    # proxy_http_version 1.1;
    # proxy_set_header Upgrade $http_upgrade;
    # proxy_set_header Connection $http_connection;

  }
}

Quellen:

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 „off“ wird auch v4 gebunden (Standard ist „on“), siehe auch: http://nginx.org/en/docs/http/ngx_http_core_module.html#listen.

listen [::]:443 ipv6only=off;