多个域名签同一张证书 nginx 配置文件范例

nginx.ssl.conf

ssl_certificate /etc/letsencrypt/live/abc.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/abc.com/privkey.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
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: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_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

nginx.conf

upstream app_backend {
    server unix:/home/username/appname/tmp/sockets/unicorn.sock fail_timeout=0;
}

server {
  listen 80;
  server_name abc.com www.abc.com;
  return 301 https://abc.com$request_uri;
}

server {
  listen 443 ssl;
  server_name www.abc.com;

  include /home/username/appname/config/nginx.ssl.conf;

  return 301 https://abc.com$request_uri;
}


server {
    gzip  on;
    gzip_disable "msie6";
    client_max_body_size 150m;

    listen 443 ssl;
    server_name abc.com;

    include /home/username/appname/config/nginx.ssl.conf;

    root /home/username/appname/public;

    access_log /home/username/appname/log/nginx_access.log;
    error_log  /home/username/appname/log/nginx_error.log;

    try_files $uri/index.html $uri.html $uri @httpapp;

    location @httpapp {
        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-Host $host;
        proxy_set_header   X-Forwarded-Server $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_buffering    on;

        proxy_pass http://app_backend;
    }

    location ~ ^(/assets) {
        access_log  off;
        expires     max;
    }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /home/username/appname/public;
    }
}
Posted on 2020-05-06

No Comments

Leave a Comment