[Nginx] 為網站加入 SSL 憑證

網站沒 SSL 憑證就是在裸奔,多少還是得加上 SSL

Nginx Config

前篇實作了Load Balnace,這次為網站加上SSL憑證,簡單調整config

server {
    # 監聽 443 port,並且後面加上 "ssl"
    listen 443 ssl;
    server_name [your web site domain];

    # 指定憑證檔案的路徑
    ssl_certificate ../[site].crt;
    ssl_certificate_key ../[site].key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    charset utf-8;

    location / {
        proxy_set_header   Host    $host;
        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;
        proxy_pass http://apps;
    }
}

upstream apps {
    server  127.0.0.1:80 max_fails=3 fail_timeout=60s;
    server  127.0.0.1:81 max_fails=3 fail_timeout=60s;
} 

接著 relaod 一下

$ nginx.exe -s reload

測試下 https 憑證有效,暫時結束這回合


Nginx: Configuring HTTPS servers

Nginx: Module ngx_http_ssl_module

配置HTTPS服务器