homestead配置ssl(https)

homestead(4.0.5)为我们提供简易创建nginx虚拟机的命令:
serve-laravel whatever.com /htdocs/whatever.com
这个命令会创建配置文件/etc/nginx/sites-available/whatever.com
其中已经写下了ssl的配置:

    listen 80;
    listen 443 ssl http2;
    server_name whatever.com;
    root "/htdocs/whatever.com";
    .....
    ssl_certificate     /etc/nginx/ssl/whatever.com.crt;
    ssl_certificate_key /etc/nginx/ssl/whatever.com.key;

在homestead的脚本文件serve-laravel.sh中有一段:

  openssl genrsa -out "$PATH_KEY" 2048 2>/dev/null
  openssl req -new -key "$PATH_KEY" -out "$PATH_CSR" -subj "/CN=$1/O=Vagrant/C=UK" 2>/dev/null
  openssl x509 -req -days 365 -in "$PATH_CSR" -signkey "$PATH_KEY" -out "$PATH_CRT" 2>/dev/null

所以在生成配置文件时,证书也生成了。

我们可以把证书/etc/nginx/ssl/whatever.com.crt导出vagrant,导入到宿主机的浏览器,设置hosts。

至此,可以用https://whatever.com访问你的项目。

你可能感兴趣的:(homestead配置ssl(https))