netlify static build station + https

Reprint [Nobita learn life - the original address: https://www.cnblogs.com/codernie/p/9062104.html ]

First, the use github or gitlab landing netlify

First, open netlify website ( https://app.netlify.com/ )

 

 

 

 

 

 

 

Then use github or gitlab account login.

 

Second, create a site based on github / gitlab warehouse

Click New site from Git button:

According to the platform where you select warehouse, one of three of the following:

Select the warehouse you need to deploy:

Set the deployment options, including three points:

  1. Deployment branch (corresponding to the figure Branch to deploy):

    As the name suggests is a branch of your git repository, the default selection is the master branch

  2. Packing command (corresponding to the Build command below):

    Is your packaging commands, such as npm run build, gulp build like; if itself is a static file, no compiler package, this column is not filled

  3. After the package directory (corresponding to the Publish directory below):

    That is, after executing the directory where a static file after packaging commands, such as dist, _site like; if itself is a static document, this column is not filled

After completing the way to deploy site click the button

 

Third, set the domain, parked domain

Be completed the second step, we can see the automated deployment is up and running, and pretty soon, our site would be able to take advantage of netlify visited domain name on the list, as shown below:

As we can see netlify randomly generated domain names under a netlify, where we can change the prefix, and bound to our own domain:

>> Change netlify domain name prefix:

First, click on the image above Site settings button, and then click Change site name at the bottom of the button, the pop-up box, enter the name you need to change the prefix, click Save, as shown below:

>> bound to under your own domain name:

首先,点击上上图中 Domain settings 按钮,然后在下方点击 Add custom domain 按钮,然后在弹出框中输入自己需要绑定的完整域名,点击保存,如下图所示:

这个时候会显示 !Check DNS configuration,因为我们还没有设置域名解析到netlify服务器,所以这个时候需要到你自己域名的相应服务商网站登录之后在需要绑定的域名下添加一条CNAME解析,解析的主机记录即对应的netlify域名值(这里即 codernie.netlify.com)

ok,过一会儿就可以使用自己的域名访问自己的网站啦

 

四、生成HTTPS证书,实现HTTPS访问

第四部中的Domain settings 中往下拉,可以看到 HTTPS 几个大字母:

点击 Verify DNS configuration 按钮,待它变成下方绿色按钮之后,再点击:

然后在弹出框中点击确认,过一会儿之后就可以使用https访问你的小站啦:

看到自己的小站前面可以有绿色的安全字样,是不是很酷炫,而且很放心,再也不用担心运营商在自己的网站上挂广告啦,哈哈哈。。。等等,是不是还差了点什么:

对啊,还没有强制跳转https,OK,继续

 

五、强制HTTP跳转HTTPS访问

在第四步 Domain settings 再往下翻一点,可以看到 Force HTTPS,只需点击 Force HTTPS 即可实现,是不是很方便,如下图:

到这里,你的网站即使用户使用http访问,也将强制跳转至https访问啦,这下可以彻底不用担下运营商给你的用户“发红包”啦!

 

六、设置redirect

利用netlify实现自动化部署和HTTPS就写到这里了,喜欢就点个赞啦。

Guess you like

Origin www.cnblogs.com/linx/p/11060215.html