美文网首页Ubuntu学步者用linux不折腾怎么行Hexo
在腾讯云VPS上部署Hexo生成的静态网页,并通过Nginx+R

在腾讯云VPS上部署Hexo生成的静态网页,并通过Nginx+R

作者: Yeyuntian | 来源:发表于2018-08-30 22:39 被阅读1次

    因为前期一直用简书上的文章记录功能,一直也想有一个自己的网站进行发布

    在这个地方我看了一些关于使用VPS构建自己的网页的文章然后就觉得可以实现

    所以弄了一个腾讯云主机作为了VPS,然后采用Hexo框架生成静态网页并且用rsync进行自动部署

    1. 在本地安装Hexo

    我采用的是Ubuntu本地系统,之前做过相关的记录所以不再赘述

    2. 在VPS上安装nginx与rsync

    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~$ ssh ubuntu@132.232.98.66 -p 22
    ubuntu@132.232.98.66's password: 
    Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-130-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    New release '18.04.1 LTS' available.
    Run 'do-release-upgrade' to upgrade to it.
    
    
    Last login: Thu Aug 30 15:55:35 2018 from 124.161.176.141
    ubuntu@VM-0-3-ubuntu:~$ sudo apt-get update
    Hit:1 http://mirrors.tencentyun.com/ubuntu xenial InRelease
    Get:2 http://mirrors.tencentyun.com/ubuntu xenial-security InRelease [107 kB]
    Get:3 http://mirrors.tencentyun.com/ubuntu xenial-updates InRelease [109 kB]
    Fetched 216 kB in 1s (153 kB/s)
    Reading package lists... Done
    ubuntu@VM-0-3-ubuntu:~$ sudo apt-get install nginx
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8
      libtiff5 libvpx3 libxpm4 libxslt1.1 nginx-common nginx-core
    Suggested packages:
      libgd-tools fcgiwrap nginx-doc ssl-cert
    The following NEW packages will be installed:
      fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8
      libtiff5 libvpx3 libxpm4 libxslt1.1 nginx nginx-common nginx-core
    0 upgraded, 14 newly installed, 0 to remove and 193 not upgraded.
    Need to get 3002 kB of archives.
    After this operation, 9785 kB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Get:1 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 libjpeg-turbo8 amd64 1.4.2-0ubuntu3.1 [111 kB]
    Get:2 http://mirrors.tencentyun.com/ubuntu xenial/main amd64 libjbig0 amd64 2.1-3.1 [26.6 kB]
    Get:3 http://mirrors.tencentyun.com/ubuntu xenial/main amd64 fonts-dejavu-core all 2.35-1 [1039 kB]
    Get:4 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 fontconfig-config all 2.11.94-0ubuntu1.1 [49.9 kB]
    Get:5 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 libfontconfig1 amd64 2.11.94-0ubuntu1.1 [131 kB]
    Get:6 http://mirrors.tencentyun.com/ubuntu xenial/main amd64 libjpeg8 amd64 8c-2ubuntu8 [2194 B]
    Get:7 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 libtiff5 amd64 4.0.6-1ubuntu0.4 [148 kB]
    Get:8 http://mirrors.tencentyun.com/ubuntu xenial/main amd64 libvpx3 amd64 1.5.0-2ubuntu1 [732 kB]
    Get:9 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 libxpm4 amd64 1:3.5.11-1ubuntu0.16.04.1 [33.8 kB]
    Get:10 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 libgd3 amd64 2.1.1-4ubuntu0.16.04.10 [126 kB]
    Get:11 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 libxslt1.1 amd64 1.1.28-2.1ubuntu0.1 [145 kB]
    Get:12 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 nginx-common all 1.10.3-0ubuntu0.16.04.2 [26.6 kB]
    Get:13 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 nginx-core amd64 1.10.3-0ubuntu0.16.04.2 [428 kB]
    Get:14 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 nginx all 1.10.3-0ubuntu0.16.04.2 [3490 B]
    Fetched 3002 kB in 1s (2345 kB/s)
    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LC_TIME = "zh_CN.UTF-8",
        LC_MONETARY = "zh_CN.UTF-8",
        LC_ADDRESS = "zh_CN.UTF-8",
        LC_TELEPHONE = "zh_CN.UTF-8",
        LC_NAME = "zh_CN.UTF-8",
        LC_MEASUREMENT = "zh_CN.UTF-8",
        LC_IDENTIFICATION = "zh_CN.UTF-8",
        LC_NUMERIC = "zh_CN.UTF-8",
        LC_PAPER = "zh_CN.UTF-8",
        LANG = "en_US.utf8"
        are supported and installed on your system.
    perl: warning: Falling back to a fallback locale ("en_US.utf8").
    locale: Cannot set LC_ALL to default locale: No such file or directory
    Preconfiguring packages ...
    Selecting previously unselected package libjpeg-turbo8:amd64.
    (Reading database ... 98938 files and directories currently installed.)
    Preparing to unpack .../libjpeg-turbo8_1.4.2-0ubuntu3.1_amd64.deb ...
    Unpacking libjpeg-turbo8:amd64 (1.4.2-0ubuntu3.1) ...
    Selecting previously unselected package libjbig0:amd64.
    Preparing to unpack .../libjbig0_2.1-3.1_amd64.deb ...
    Unpacking libjbig0:amd64 (2.1-3.1) ...
    Selecting previously unselected package fonts-dejavu-core.
    Preparing to unpack .../fonts-dejavu-core_2.35-1_all.deb ...
    Unpacking fonts-dejavu-core (2.35-1) ...
    Selecting previously unselected package fontconfig-config.
    Preparing to unpack .../fontconfig-config_2.11.94-0ubuntu1.1_all.deb ...
    Unpacking fontconfig-config (2.11.94-0ubuntu1.1) ...
    Selecting previously unselected package libfontconfig1:amd64.
    Preparing to unpack .../libfontconfig1_2.11.94-0ubuntu1.1_amd64.deb ...
    Unpacking libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
    Selecting previously unselected package libjpeg8:amd64.
    Preparing to unpack .../libjpeg8_8c-2ubuntu8_amd64.deb ...
    Unpacking libjpeg8:amd64 (8c-2ubuntu8) ...
    Selecting previously unselected package libtiff5:amd64.
    Preparing to unpack .../libtiff5_4.0.6-1ubuntu0.4_amd64.deb ...
    Unpacking libtiff5:amd64 (4.0.6-1ubuntu0.4) ...
    Selecting previously unselected package libvpx3:amd64.
    Preparing to unpack .../libvpx3_1.5.0-2ubuntu1_amd64.deb ...
    Unpacking libvpx3:amd64 (1.5.0-2ubuntu1) ...
    Selecting previously unselected package libxpm4:amd64.
    Preparing to unpack .../libxpm4_1%3a3.5.11-1ubuntu0.16.04.1_amd64.deb ...
    Unpacking libxpm4:amd64 (1:3.5.11-1ubuntu0.16.04.1) ...
    Selecting previously unselected package libgd3:amd64.
    Preparing to unpack .../libgd3_2.1.1-4ubuntu0.16.04.10_amd64.deb ...
    Unpacking libgd3:amd64 (2.1.1-4ubuntu0.16.04.10) ...
    Selecting previously unselected package libxslt1.1:amd64.
    Preparing to unpack .../libxslt1.1_1.1.28-2.1ubuntu0.1_amd64.deb ...
    Unpacking libxslt1.1:amd64 (1.1.28-2.1ubuntu0.1) ...
    Selecting previously unselected package nginx-common.
    Preparing to unpack .../nginx-common_1.10.3-0ubuntu0.16.04.2_all.deb ...
    Unpacking nginx-common (1.10.3-0ubuntu0.16.04.2) ...
    Selecting previously unselected package nginx-core.
    Preparing to unpack .../nginx-core_1.10.3-0ubuntu0.16.04.2_amd64.deb ...
    Unpacking nginx-core (1.10.3-0ubuntu0.16.04.2) ...
    Selecting previously unselected package nginx.
    Preparing to unpack .../nginx_1.10.3-0ubuntu0.16.04.2_all.deb ...
    Unpacking nginx (1.10.3-0ubuntu0.16.04.2) ...
    Processing triggers for libc-bin (2.23-0ubuntu9) ...
    Processing triggers for man-db (2.7.5-1) ...
    Processing triggers for ureadahead (0.100.0-19) ...
    Processing triggers for ufw (0.35-0ubuntu2) ...
    Processing triggers for systemd (229-4ubuntu21.2) ...
    Setting up libjpeg-turbo8:amd64 (1.4.2-0ubuntu3.1) ...
    Setting up libjbig0:amd64 (2.1-3.1) ...
    Setting up fonts-dejavu-core (2.35-1) ...
    Setting up fontconfig-config (2.11.94-0ubuntu1.1) ...
    Setting up libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
    Setting up libjpeg8:amd64 (8c-2ubuntu8) ...
    Setting up libtiff5:amd64 (4.0.6-1ubuntu0.4) ...
    Setting up libvpx3:amd64 (1.5.0-2ubuntu1) ...
    Setting up libxpm4:amd64 (1:3.5.11-1ubuntu0.16.04.1) ...
    Setting up libgd3:amd64 (2.1.1-4ubuntu0.16.04.10) ...
    Setting up libxslt1.1:amd64 (1.1.28-2.1ubuntu0.1) ...
    Setting up nginx-common (1.10.3-0ubuntu0.16.04.2) ...
    locale: Cannot set LC_ALL to default locale: No such file or directory
    Setting up nginx-core (1.10.3-0ubuntu0.16.04.2) ...
    Setting up nginx (1.10.3-0ubuntu0.16.04.2) ...
    Processing triggers for libc-bin (2.23-0ubuntu9) ...
    Processing triggers for systemd (229-4ubuntu21.2) ...
    Processing triggers for ureadahead (0.100.0-19) ...
    Processing triggers for ufw (0.35-0ubuntu2) ...
    ubuntu@VM-0-3-ubuntu:~$ tree /etc/nginx/
    /etc/nginx/
    ├── conf.d
    ├── fastcgi.conf
    ├── fastcgi_params
    ├── koi-utf
    ├── koi-win
    ├── mime.types
    ├── nginx.conf
    ├── proxy_params
    ├── scgi_params
    ├── sites-available
    │   └── default
    ├── sites-enabled
    │   └── default -> /etc/nginx/sites-available/default
    ├── snippets
    │   ├── fastcgi-php.conf
    │   └── snakeoil.conf
    ├── uwsgi_params
    └── win-utf
    
    4 directories, 14 files
    
    已经安装完成了nginx软件
    接下来在服务器端安装rsync
    ubuntu@VM-0-3-ubuntu:~$ sudo apt-get install rsync
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    rsync is already the newest version (3.1.1-3ubuntu1.2).
    0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
    
    我的已经安装好了所以就这样的
    然后配置nginx的服务端文件
    ubuntu@VM-0-3-ubuntu:~$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/hexo
    ubuntu@VM-0-3-ubuntu:~$ sudo ln -s /etc/nginx/sites-available/hexo /etc/nginx/sites-enabled/hexo
    ubuntu@VM-0-3-ubuntu:~$ sudo rm /etc/nginx/sites-enabled/default
    ubuntu@VM-0-3-ubuntu:~$ tree /etc/nginx/
    /etc/nginx/
    ├── conf.d
    ├── fastcgi.conf
    ├── fastcgi_params
    ├── koi-utf
    ├── koi-win
    ├── mime.types
    ├── nginx.conf
    ├── proxy_params
    ├── scgi_params
    ├── sites-available
    │   ├── default
    │   └── hexo
    ├── sites-enabled
    │   └── hexo -> /etc/nginx/sites-available/hexo
    ├── snippets
    │   ├── fastcgi-php.conf
    │   └── snakeoil.conf
    ├── uwsgi_params
    └── win-utf
    
    4 directories, 15 files
    ubuntu@VM-0-3-ubuntu:~$ vim /etc/nginx/sites-available/hexo 
    #需要修改的地方我在下面做了注释
    ubuntu@VM-0-3-ubuntu:~$ cat /etc/nginx/sites-available/hexo 
    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
    
    # Default server configurationm                                                    4,1           Top
    #
    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
    
        root /www/hexo;    ###这个地方是填写到时候通过rsync推送到的文件位置,这个文件位置需要mkdir来建立
    
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    
        server_name yeyuntian.tech www.yeyuntian.tech yeyuntianbio.cn www.yeyuntianbio.cn; ###这个地方是写你后期设置的网站的域名,需要解析才能使用
    
        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
        }
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #   include snippets/fastcgi-php.conf;
        #
        #   # With php7.0-cgi alone:
        #   fastcgi_pass 127.0.0.1:9000;
        #   # With php7.0-fpm:
        #   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #   deny all;
        #}
    }
    
    
    # Virtual Host configuration for example.com
    #
    # You can move that to a different file under sites-available/ and symlink that
    # to sites-enabled/ to enable it.
    #
    #server {
    #   listen 80;
    #   listen [::]:80;
    #
    #   server_name example.com;
    #
    #   root /var/www/example.com;
    #   index index.html;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
    #   }
    #}
    ubuntu@VM-0-3-ubuntu:~$ mkdir /www/hexo
    

    3. 本地电脑的hexo配置文件修改

    我们把配置好了过后就需要在本地进行配置了
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ vim _config.yml
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ cat _config.yml
    # Hexo Configuration
    ## Docs: https://hexo.io/docs/configuration.html
    ## Source: https://github.com/hexojs/hexo/
    
    # Site
    title: Yeyuntian # 博客的名字
    subtitle: Yeyuntian.bio # 博客副标题 
    author: Yeyuntian # 博客的作者
    language: 
    timezone: 
    
    # custom Site settings
    # more detail check out docs
    SEOTitle: Yeyuntian # 这个标题是放在浏览器抬头的那个标题 
    header-img: http://pe5p1h4fc.bkt.clouddn.com/head.jpg
    email: Yeyuntian@sicau.edu.cn  
    description: "叶云天的个人博客"
    keyword: # seo key words
    
    favicon: http://pe5p1h4fc.bkt.clouddn.com/head.jpg # your favicon png 网页标签图标 建议用小图片 
    # custom end
    
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: http://haojen.github.io
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
    
    # SNS settings
    # RSS:
    weibo_username: haojen
    zhihu_username: megahertz
    github_username: haojen
    twitter_username: ehazon
    facebook_username:  
    linkedin_username:  
    
    # Build settings
    anchorjs: false                        # if you want to customize anchor. check out line:181 of `post.html`
    
    
    # Disqus settings 
    disqus_username: 
    
    # Duoshuo settings
    duoshuo_username:  # 你的多说帐号
    # Share component is depend on Comment so we can NOT use share only.
    duoshuo_share: true                     # set to false if you want to use Comment without Sharing
    
    # Use livere
    use_livere:
    
    # Valine comment system https://valine.js.org
    valine: 
      enable: false
      appid:  #Leancloud应用的appId
      appkey:  #Leancloud应用的appKey
      verify: false #验证码
      notify: false #评论回复提醒
      avatar: mm #评论列表默认头像样式
      placeholder: Just go go #评论框占位符
    
    # Analytics settings
    # Baidu Analytics
    ba_track_id:
    # Google Analytics
    ga_track_id:             # Format: UA-xxxxxx-xx
    ga_domain:
    
    # Sidebar settings
    sidebar-about-description: 生而孤独 活而精彩 1013072239@qq.com  # 个人描述
    sidebar-avatar: http://pe5p1h4fc.bkt.clouddn.com/head.jpg    # use absolute URL
    
    
    # Featured Tags
    featured-tags: true                     # whether or not using Feature-Tags
    featured-condition-size: 1              # A tag will be featured if the size of it is more than this condition value
    
    # friends
    friends:  # 友链
    
    # Directory
    source_dir: source
    public_dir: public
    tag_dir: tags
    archive_dir: archives
    category_dir: categories
    code_dir: downloads/code
    i18n_dir: :lang
    skip_render:
    
    # Writing
    new_post_name: :title.md # File name of new posts
    default_layout: post
    titlecase: false # Transform title into titlecase
    external_link: true # Open external links in new tab
    filename_case: 0
    render_drafts: false
    post_asset_folder: true
    relative_link: false
    future: true
    highlight:
      enable: true
      line_number: false
      auto_detect: false
      tab_replace:
    
    # Category & Tag
    default_category: uncategorized
    category_map:
    tag_map:
    
    # Date / Time format
    ## Hexo uses Moment.js to parse and display date
    ## You can customize the date format as defined in
    ## http://momentjs.com/docs/#/displaying/format/
    date_format: YYYY-MM-DD
    time_format: HH:mm:ss
    
    # Pagination
    ## Set per_page to 0 to disable pagination
    per_page: 8
    pagination_dir: page
    
    # Extensions
    ## Plugins: https://hexo.io/plugins/
    
    markdown:
      plugins:
        - markdown-it-abbr
        - markdown-it-footnote
        - markdown-it-ins
        - markdown-it-sub
        - markdown-it-sup
        - markdown-it-emoji
    
    ## Themes: https://hexo.io/themes/
    theme: Anisina
    
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type: rsync
      host: 132.232.98.66 
      user: ubuntu
      root: /www/hexo
      prot: 22
    
    
    # img CDN path
    cdn-url:  # 你的CDN地址
    
    # Qiniu imageView2 API
    # More info http://developer.qiniu.com/code/v6/api/kodo-api/image/imageview2.html
    clip-content: "?imageView2/1/w/1400/h/400/interlace/1/q/90"
    clip-avatar: "?imageView2/2/w/300/h/300/interlace/1/q/90"
    clip-home-post-bg: "?imageView2/1/w/800/h/300/interlace/1/q/70"
    
    # post default images 
    post-default-img: http://pe5p1h4fc.bkt.clouddn.com/head.jpg #博文默认的图片
    post-default-img-mobile: http://pe5p1h4fc.bkt.clouddn.com/head.jpg #移动端显示的图片
    
    # search api , set your custom key
    swiftype_key: 
    
    
    # archive page title 
    archive:
        title: archives
        description: 可以根据归档日期检索所有文件
    
    本地是要配置_config.yml中关于deploy的相关配置
    deploy:
      type: rsync  ###推送软件的名字(有的地方 是用git来实现的推送)
      host: 132.232.98.66  ###远端服务器的IP地址
      user: ubuntu  ###登录远端服务器的登录名
      root: /www/hexo ###这个是远端用于储存的文件夹,这个要和在服务器上的设置接受的文件夹要一致
      prot: 22  ###这个不用变
    

    4. 本地与远端服务器的通道建立

    简单一点讲,就是一旦我这边的本地电脑进行了deploy,然后就要通过一个方式传递给远端的VPS。这个传送的过程就需要登录服务器进行传送,因此要实现这个通道登录传送的自动化。
    我们在这里选择的是ssh进行登录传送
    首先得设置公钥和私钥
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ ssh-keygen -t rsa -C 'tenxunvps'
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/yeyuntian/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/yeyuntian/.ssh/id_rsa.
    Your public key has been saved in /home/yeyuntian/.ssh/id_rsa.pub.
    
    这个完成后会在对应的文件夹中形成一对秘钥对
    我们需要将公钥.pub这个复制到服务器的
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ scp /home/yeyuntian/blog/id_rsa.pub ubuntu@132.232.98.66:~/.ssh/
    ubuntu@132.232.98.66's password: 
    id_rsa.pub                                                         100%  391     0.4KB/s   00:00  
    
    然后就可以在远端服务器中看到这个了
    ubuntu@VM-0-3-ubuntu:~/.ssh$ l
    authorized_keys  id_rsa.pub
    
    然后我们把这个东西附加到已经存在的authorized_keys 中
    ubuntu@VM-0-3-ubuntu:~/.ssh$ cat id_rsa.pub >> authorized_keys 
    
    最后有一个问题就是我们每次都要去记住远端服务器的IP才能登录
    所以我们可以通过秘钥对来进行简化登录
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ sudo vim ~/.ssh/config 
    [sudo] password for yeyuntian:
    #修改这个文件成为这样
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ cat ~/.ssh/config 
    Host coding.net
        IdentityFile ~/.ssh/id_rsa.coding
        User yeyuntian
    Host    tenxunvps
        HostName    132.232.98.66
        Port    22
        User    ubuntu
        IdentityFile    ~/.ssh/id_rsa
    #然后我们就可以通过tenxunvps这个来替代IP
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ ssh ubuntu@tenxunvps
    Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-130-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    New release '18.04.1 LTS' available.
    Run 'do-release-upgrade' to upgrade to it.
    
    
    *** System restart required ***
    Last login: Thu Aug 30 20:15:15 2018 from 124.161.176.141
    ubuntu@VM-0-3-ubuntu:~$ exit
    logout
    Connection to 132.232.98.66 closed.
    

    可以看到通过密钥对是可以顺畅登录远端VPS的

    5. 推送Hexo生成的静态网页到远端服务器

    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ hexo clean
    INFO  Deleted database.
    INFO  Deleted public folder.
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ hexo g
    INFO  Start processing
    INFO  Files loaded in 414 ms
    INFO  Generated: index.html
    INFO  Generated: archives/index.html
    INFO  Generated: fonts/glyphicons-halflings-regular.woff
    INFO  Generated: fonts/glyphicons-halflings-regular.eot
    INFO  Generated: fonts/glyphicons-halflings-regular.woff2
    INFO  Generated: fonts/glyphicons-halflings-regular.ttf
    INFO  Generated: archives/2018/08/index.html
    INFO  Generated: fonts/glyphicons-halflings-regular.svg
    INFO  Generated: archives/2018/index.html
    INFO  Generated: css/syntax.css
    INFO  Generated: js/jquery.tagcloud.js
    INFO  Generated: js/blog.js
    INFO  Generated: js/totop.js
    INFO  Generated: css/blog-style.css
    INFO  Generated: js/bootstrap.min.js
    INFO  Generated: js/jquery.min.js
    INFO  Generated: css/bootstrap.min.css
    INFO  Generated: js/jquery.js
    INFO  Generated: 2018/08/28/hello-world/index.html
    INFO  19 files generated in 336 ms
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ hexo s
    INFO  Start processing
    INFO  Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
    ^CINFO  Have a nice day
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ hexo d
    INFO  Deploying: rsync
    sending incremental file list
    rsync: failed to set times on "/www/hexo/.": Operation not permitted (1)
    ./
    index.html
    rsync: recv_generator: mkdir "/www/hexo/2018" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/archives" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/css" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/fonts" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/js" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    2018/
    archives/
    css/
    fonts/
    js/
    rsync: mkstemp "/www/hexo/.index.html.IqUXOd" failed: Permission denied (13)
    
    sent 5,059 bytes  received 937 bytes  2,398.40 bytes/sec
    total size is 806,290  speedup is 134.47
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.1]
    FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
    Error: rsync: failed to set times on "/www/hexo/.": Operation not permitted (1)
    rsync: recv_generator: mkdir "/www/hexo/2018" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/archives" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/css" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/fonts" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: recv_generator: mkdir "/www/hexo/js" failed: Permission denied (13)
    *** Skipping any contents from this failed directory ***
    rsync: mkstemp "/www/hexo/.index.html.IqUXOd" failed: Permission denied (13)
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.1]
    
        at ChildProcess.<anonymous> (/home/yeyuntian/blog/node_modules/hexo-util/lib/spawn.js:37:17)
        at emitTwo (events.js:126:13)
        at ChildProcess.emit (events.js:214:7)
        at maybeClose (internal/child_process.js:925:16)
        at Socket.stream.socket.on (internal/child_process.js:346:11)
        at emitOne (events.js:116:13)
        at Socket.emit (events.js:211:7)
        at Pipe._handle.close [as _onclose] (net.js:557:12)
    
    我们在这里看到了一个问题,就是实际上并不能推送,原因就是没有权限我们进一步看一下VPS上这/www文件夹权限我们看到
    ubuntu@VM-0-3-ubuntu:/www$ ll
    total 12
    drwxr-xr-x  3 root root 4096 Aug 30 18:57 ./
    drwxr-xr-x 25 root root 4096 Aug 30 20:23 ../
    drwxr-xr-x  2 root root 4096 Aug 30 18:57 hexo/
    
    这个问题十分好解决,就是修改一下这个文件夹的归属就好了,另外他们的子文件夹都需要修改
    修改好了再试一试就没有问题了
    ubuntu@VM-0-3-ubuntu:/$ sudo chown ubuntu:ubuntu /www/
    ubuntu@VM-0-3-ubuntu:/www$ sudo chown ubuntu:ubuntu *
    
    最后再试着推送一下就可以看到没有问题了
    yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/blog$ hexo d
    INFO  Deploying: rsync
    sending incremental file list
    ./
    index.html
    2018/
    2018/08/
    2018/08/28/
    2018/08/28/hello-world/
    2018/08/28/hello-world/index.html
    archives/
    archives/index.html
    archives/2018/
    archives/2018/index.html
    archives/2018/08/
    archives/2018/08/index.html
    css/
    css/blog-style.css
    css/bootstrap.min.css
    css/syntax.css
    fonts/
    fonts/glyphicons-halflings-regular.eot
    fonts/glyphicons-halflings-regular.svg
    fonts/glyphicons-halflings-regular.ttf
    fonts/glyphicons-halflings-regular.woff
    fonts/glyphicons-halflings-regular.woff2
    js/
    js/blog.js
    js/bootstrap.min.js
    js/jquery.js
    js/jquery.min.js
    js/jquery.tagcloud.js
    js/totop.js
    
    sent 271,687 bytes  received 440 bytes  544,254.00 bytes/sec
    total size is 806,290  speedup is 2.96
    INFO  Deploy done: rsync
    

    最后上一张网站的样式图

    还没有做网址解析

    网站样式

    相关文章

      网友评论

        本文标题:在腾讯云VPS上部署Hexo生成的静态网页,并通过Nginx+R

        本文链接:https://www.haomeiwen.com/subject/uikdwftx.html