在本地開發環境中,常經過配置host來使用域名,那麼怎麼使用https呢,https須要證書支持,而證書須要ca機構來發布,那怎麼在本地實現一個證書呢?html
$brew install openssl
sudo openssl req \ -x509 \ -nodes \ -days 365 \ -newkey rsa:2048 \ -keyout example.key \ -out example.crt
其中最重要的一個問題是 Common Name,正常狀況下應該填入一個域名,這裏能夠填 127.0.0.2node
當前目錄下出現example.key和example.crt兩個文件nginx
$ mkdir conf/certs $ mv example.crt example.key conf/certs
$vim conf/conf.d/default.conf server { listen 443 ssl; server_name localhost; ssl on; ssl_certificate /etc/nginx/certs/example.crt; ssl_certificate_key /etc/nginx/certs/example.key; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root /usr/share/nginx/html; index index.html index.htm; } }