nginx配置 http+https服務

先執行brew install nginx安裝 nginx

然後到nginx conf.d 目錄裡,增加兩個 *.conf 文件 默認是 /etc/nginx/conf.d/ 文件夾內

# here is yourdomain.conf
server {  
       listen         80;
       server_name    yourdomain.com;
       return         301 https://$server_name$request_uri;
}
# here is yourdomain.ssl.conf
server {  
  listen  443;
  server_name yourdomain.com;
  ssl on;
  ssl_certificate /etc/ssl/certs/myssl.crt;
  ssl_certificate_key /etc/ssl/private/myssl.key;
  ssl_prefer_server_ciphers       on;
# ...
# rest of config here
# ...
}

配置完成后,只要執行 sudo service nginx restart 就會生效