部署一个网站需要三个步骤:(1) generating the site, (2) deploying it to the public Internet, and (3) assigning it a custom domain name. 下面就每一步做详细解释:

1.网站的生成

Jekyll是一个常用的简单地网站生成器。

1.1 首先,安装jekyll,打开终端,输入以下命令:

,如果权限不够,改为输入sudo gem install jekyll.

安装成功后会提示:

1.2 生成静态网页:首先我们要用jekyll的new 命令去生成一个目录,这个目录包含了你的网站的所有默认内容。在终端输入:

即生成了一个my-portfolio-site的网站目录,用ls命令可以去查看证实你的目录是否成功生成。

1.3 网站预览:要想在本地查看你的网站,首先你要用cd 命令进入你的网站目录,在该目录下输入

这个命令开启了一个本地的服务器,将你的文件提交到你的电脑,如果你想查看你对网站做出的修改,这条命令也是必要的。

默认的,jekyll的这个serve命令创建的本地服务器地址为http://localhost:4000/

打开浏览器,输入http://localhost:4000/。即可看到:

1.4 jekyll的目录结构

jekyll生成的网站和你自己建立的是不同的,它提供了一个标准的目录结构和组成部分,帮助你快速开发。下面来了解一下jekyll默认的网站目录结构和内容:

  1. _config.yml - 这是一个你只需要编辑一次的配置文件,需要配置的变量包括你网站的title,你的邮箱等。

  2. _includes/ - 这个目录包含了你网站要重复加载的相同部分,比如网站的header和footer。

  3. _posts/ -这个目录是用来存储blog posts,可以添加新的blog,可以根据网站的style进行渲染,只要文件名遵从jekyll的标准命名规则。

  4. _layouts/ -这个目录包含 该目录包含了用于设计某些类型的站点内的职位模板。例如,新的博客文章将使用post.html定义的HTML布局。

2. 部署你的网站到GitHub上的页面

有许多不同的方式来部署一个网站到公共互联网。在这个里,将使用GitHub的页面来部署自己的网站,因为GitHub上的页面为jekyll提供了丰富的集成和支持。 首先,创建一个github账号,这里不多赘述。接下来在 GitHub页面上新建一个repository用来存储你网站的内容。你的repository必须符合GitHub Page的命名规则,否则你的站点无法发布。具体的,应以以下形式命名repository:

下面,我们将使用git将你的站点目录push到你的新repo中,在这之前,我们先初始化你站点目录里的 Git repository

使用cd命令进入你的站点目录,输入以下命令初始化 Git repository

接着,Git需要知道哪个repo来存储你的站点,也就是我们之前建立的新repo,为了通过git明确是这个repo,我们需要添加一个remote,并且标签器为origin,remote是这个用来存储你的站点的repo的url,origin是remote的别名,可以把别名视为一个简称或者替代名,这就意味着不需要每次输入冗长的remote URL , 你只需要稍后将它指向origin即可。用如下命令在终端中添加remote:

If you accidentally make a mistake when adding the remote URL, you can start over and remove the remote with the following command:

为了确认remote是否成功添加,可输入:

通过下述命令添加你站点内的所有内容:

commit可以保存你对网站的修改和变化:

现在我们将用git的push命令将你的站点内容push到你的repo中:

回顾一下步骤2 :

Let's review what you accomplished in this unit:

  1. Created a GitHub account
  2. Created the required GitHub repo
  3. Used Git to add, commit, and push your website to the repo
  4. Succesfully used GitHub Pages to deploy your site to the Internet!

3.Assign a Custom Domain Name to Your Website  指定自定义域名到您的网站

去AWS(amazon web services)买域名,然后:

  1. Inform GitHub of the new domain name we'll be using (the one you purchased)
  2. Set up DNS records in Route 53 that direct to GitHub

具体操作为:

  1. open GitHub and access the repo you created earlier titled your-user-name.github.io.

  2. Click the "New file" button.

  3. Name the new file CNAME. Do not add a file name extension.

  4. In the file, on line 1, type the custom domain name you just purchased in the following format:

    You may have purchased a domain name with a TLD other than .com. In that case, make sure to use that TLD when creating the CNAME file.

  5. Commit the new file

  6. Under the title of the repo, click on "Settings." Scroll down to the section titled "GitHub Pages" and confirm that there is a message similar to the following:

  7. Next, we have to let the rest of the Internet know that we want to associate the custom domain name with your GitHub Pages site.We can do this by creating DNS records, which are globally accessible records that map domain names to servers.The DNS records are created inside of a Hosted Zone in Route 53. A Hosted Zone is essentially a group of DNS records for a single domain.
  8. access Route 53 once again. On the left side of the page, click on the title that says "Hosted Zones." Notice that you have a Hosted Zone for your new domain name.
  9. Domain names are associated with the correct DNS records by setting the domain name's name servers.

    After a domain name is typed into a browser, the computer first retrieves the name servers that correspond to that domain name. The name servers are important because they're responsible with providing the computer with other important information (in the form of DNS records) associated with the domain name.

    Setting your domain's name servers is important. The DNS is a global system, which means that anyone can create DNS records. We must verify that the DNS records we create were actually created by the owner of the domain name (in this case, you).

    By doing this, the owner of a domain name ensures that only they have exclusive control over their domain's DNS records.

     
    1. Notice that the Hosted Zone for your domain name already has an NS(Name server) record. This record contains four values. These are the Hosted Zone's unique name servers. Take note of these values and copy them down somewhere.

    2. On the left hand side, under "Domains," click on "Registered domains." Then, click on your domain name.

    3. On the right hand side of the page, locate the section titled "Name Servers." Notice that these are the same name servers that your Hosted Zone's NS record contained. Route 53 did this for you automatically.

    10.Now that your domain name is associated with the correct name servers, it's time to create some additional DNS records within the Hosted Zone.

    The records that we'll create will be used by the name servers to help locate your site when a computer wants to load it. Specifically, the name servers will be responsible for providing that computer with important information stored in the records.

    There are several different types of DNS records.

    We're going to start by creating an Arecord, which stands for Address record.

    An A record directs a domain name to an IP address. This record will associate our new custom domain name with Github's servers.

    1. inside of your Hosted Zone, click on the button at the top labeled "Create Record Set." A form will appear to the right. Leave the "Name:" field blank. Set the "Type:" field toA - IPv4 address.

    2. Leave the "TTL (Seconds)" value at the default of 300.

    3. In the "Value" text box, enter the following IP addresses (keep them on separate lines):

      These IP addresses belong to GitHub. We are specifying that when your custom domain name is requested, the DNS should direct the request to GitHub.

    4. Click the "Save Record Set" button at the bottom of the form.

    11.

    When setting up a website, it's also conventional to also set up a wwwsubdomain. www stands forworld wide web.

    Subdomains are part of a main (or root) domain. For example,www.yourcustomdomain.com is a subdomain of theyourcustomdomain.com root domain.

    We can set up a subdomain using aCNAME record, which stands forCanonical Name.

    CNAME record specifies that a domain name will be used as an alias, or substitute, for the true (canonical) domain name.

      1. Inside of your Hosted Zone, click on the button at the top labeled "Create Record Set".

    A form will appear to the right. In the "Name:" field, enter only www. Set the "Type: " field toCNAME - Canonical name. This step sets up the subdomain.

      2. In the Value text box, enter the domain name that GitHub assigned to you earlier (the canonical domain name:

      3.Click the "Save Record Set" button at the bottom of the form.

    Let's review your DNS setup so far.

    In Route 53, your domain name's Hosted Zone contains the following:

    1. The NS (Name Server) record for your domain name. When a domain name is typed into a browser, the DNS looks to these name servers to help direct the request.

    2. The A (or Alias) record. This record is used to direct requests of your domain name to GitHub's servers using their IP addresses.

    3. The CNAME (or Canonical name) record. This record specifies what custom domain will point to your true (canonical) domain.

    You've now created two DNS records: anA record for yourcustomdomain.comand a CNAME record forwww.yourcustomdomain.com. Let's make sure they both work.

    1. try opening your website using your root domain in the web browser. You should see your new GitHub Pages site.

    2. Try opening your website using yourwww subdomain in the web browser. You should see your new GitHub Pages site.

    Note: It may take a few minutes for the DNS record to take effect.

    Success! Your website should now display in the browser when you navigate to your custom domain name.

    The DNS may take some time to update records. If your site still doesn't load in the browser using your custom domain name, simply wait a few minutes.

    We can also use the dig command in the terminal to look up your domain name and make sure that the CNAME and A records were properly set.

    The dig (domain information groper) command is a DNS lookup utility. It can be used for a variety of things. In this case, we will use it to verify your domain name's DNS records.

     
    1. Let's confirm that your DNS records are correct. Type the following into the terminal:
    dig www.yourcustomdomain.com

    If all is correct, you should see an A (forA record) in the output along with the two IP addresses we added for the A record.

    You should also see CNAME in the output along with your custom domain name and the GitHub default domain name.

通过jekyll建立静态网页的更多相关文章

  1. 第一次在Django上编写静态网页

    新建一个Python Django工程: Win+R进入cmd命令界面,并cd到指定工程目录下,比如我的工程目录是E:\wamp\Apache24\www\ 输入E: 跳转E盘 输入cd wamp\A ...

  2. 静态网页VS动态网页

    干<沙朗新闻发布系统>什么时候.我们已经建立的网页.html的,并且.aspx,第一次接触.我认为这些东西是一样的,因为它,在观看ASP.NET视频的时候.听见里面讲课的老师有提到了这两样 ...

  3. 【Node.js】利用node.js搭建服务器并访问静态网页

    node.js是一门服务端的语言,下面讲讲如何利用node.js提供给我们的api来搭建服务器,并且访问静态网页 项目结构如下 ------------------------------------ ...

  4. Freemarker入门小案例(生成静态网页的其中一种方式)

    其实生成静态网页的方式有好多种,我昨天看了一下,Freemarker是其中一种,但是Freemarker现在我们都用得比较少了,现在用得ActiveMQ用来发送信息到静态页面,不过想了一下这个小东西, ...

  5. Nginx-HTTP之静态网页访问流程分析一

    假设访问静态网页的配置如下: worker_processes 1; error_log stderr debug; daemon off; master_process on; events { w ...

  6. [Python] 爬虫系统与数据处理实战 Part.1 静态网页

    爬虫技术基础 HTTP/HTTPS(7层):应用层,浏览器 SSL:加密层,传输层.应用层之间 TCP/IP(4层):传输层 数据在传输过程中是加密的,浏览器显示的是解密后的数据,对爬虫没有影响 中间 ...

  7. MWeb 1.4 新功能介绍一:引入文件夹到 MWeb 中管理,支持 Octpress、Jekyll 等静态博客拖拽插入图片和实时预览

    之前在 MWeb 中打开非文档库中的 Markdown 文档,如果文档中有引用到本机图片,是没办法在 MWeb 中显示出来和预览的.这是因为 Apple 规定在 Mac App Store(MAS) ...

  8. HTML静态网页 标签、表格

    HTML静态网页: 打开DREAMWEAVER,新建HTML,如下图: body的属性: bgcolor 页面背景色 background  背景壁纸.图片 text  文字颜色 topmargin ...

  9. html部分---认识html静态网页;

    html分类:1.静态网页(html/htm)               2.动态网页              区别:动态网页不需要改动源代码,容易修改 css样式表:美化网页 js:脚本语言,增 ...

随机推荐

  1. bootstrap 学习笔记

    bootstrap作为当下的流行框架不知道它怎么能行呢? 之前也看过好多bootstrap的网上教程,可是发现光看真的记不住,说起来也真是忧桑~重点还是要自己做才是真正的印象深刻.后来我发现解析模板是 ...

  2. 桥牌笔记:Show up Squeeze显露挤牌法

    南主打4S,注意一个叫牌过程,西家叫过加倍,东家应叫过2D. 西连打红桃K.A,然后再打红桃J让东家将吃.东家上手后,回小方块.此时庄家已经失了3墩了,如何完成这个4S? 庄家必须拿到所有剩下的牌墩. ...

  3. Spring(四)Bean注入方试

    一.构造方法注入 定义:通过构造函数来完成依赖关系的设定 优缺点: 在构造对象的同时,完成依赖关系的建立 如果关联的对象很多,那和不得不在构造方法上加入过多的参数 基中有index:如果指定索引从0开 ...

  4. 【转】IOS中各种常用控件的默认高度,很全

    1.状态栏 状态栏一般高度为20像素,在打手机或者显示消息时会放大到40像素高,注意,两倍高度的状态栏在好像只能在纵向的模式下使用.如下图   用户可以隐藏状态栏,也可以将状态栏设置为灰色,黑色或者半 ...

  5. Swift学习--常量.变量.数据类型的使用(一)

    一.Swift中的常量和变量 /* Swift 中定义常量和变量用let/var let 代表定义一个常量 var 代表定义一个变量 Swift 中代表定义常量和变量不需要写数据类型,编译器辉根据我们 ...

  6. Swift之map函数的强大之处

    CollectionType Map 在CollectionType的extension中map方法的定义: extension CollectionType { /// Return an `Arr ...

  7. 捡火柴的Nova君(n个线段相交问题)

    题目来源:https://biancheng.love/contest-ng/index.html#/41/problems 捡火柴的Nova君 题目描述 南方没暖气,怕冷的的宝宝们只能用火柴取暖.然 ...

  8. java 的方法注释写在哪里?

    如果有接口,写在接口方法上即可.鼠标滑过方法名时时会显示 如果没有接口,写在每个方法上方. eclipse 分三步 ① 找到方法,并将光标移动至方法名的上方 ②/** ③回车 那,效果是酱紫

  9. (转)为什么大公司青睐Java

    转自 http://www.zhihu.com/question/25908953/answer/32119971 因为这是一个商业问题,不是技术问题. 我在面试时探讨过这个问题,对方创业期,问我如果 ...

  10. Openstack python api 学习文档 api创建虚拟机

    Openstack python api 学习文档 转载请注明http://www.cnblogs.com/juandx/p/4953191.html 因为需要学习使用api接口调用openstack ...