# Nginx conf 內部網址綁自產SSL憑證 ###### tags: `Nginx` 安裝 openssl 套件 ## 1. 產生 Key 並設定有效時長 ```shell= openssl genrsa 1024 > 你的網址.key ``` ## 2. 使用 key 製作 csr 檔 ```shell= openssl req -new -key 你的網址.key > 你的網址.csr ``` ## 3. 將 csr 檔轉成 crt 檔 ```shell= openssl req -x509 -key 你的網址.key -in 你的網址.csr > 你的網址.crt ``` ## 4. 將 key 與 crt 檔移至 nginx conf 內的 key 目錄下,以便管理 ```shell= mv 你的網址.key /etc/nginx/conf.d/key mv 你的網址.crt /etc/nginx/conf.d/key ``` ## 5. nginx conf 掛上 ssl ```shell= server { listen 80; server_name 你的域名; rewrite ^(.*)$ https://$host$1 permanent; } server { listen 443 ssl; server_name 你的域名; ssl_certificate /etc/nginx/conf.d/key/你的網址.crt; # crt檔位置 ssl_certificate_key /etc/nginx/conf.d/key/你的網址.key; # key檔案位置 } ``` ### 若需強轉443,補上resrite ```shell= server { listen 80; server_name 你的域名; rewrite ^(.*)$ https://$host$1 permanent; # 強轉ssl } server { listen 443 ssl; server_name 你的域名; ssl_certificate /etc/nginx/conf.d/key/你的網址.crt; # crt檔位置 ssl_certificate_key /etc/nginx/conf.d/key/你的網址.key; # key檔案位置 } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up