我是如何搭建起这个网站的


title: 我是如何搭建起这个网站的
date: 2017-7-24 19:51:15
tags: [网站维护,Linux,Hexo]
---

本文只是做个记录

(老博客平台)

前期准备

域名

域名(Domain Name),是由一串用点分隔的字符组成的Internet上某一台计算机或计算机组的名称,用于在数据传输时标识计算机的电子方位(有时也指地理位置,地理上的域名,指代有行政自主权的一个地方区域)。域名是一个IP地址上有“面具” 。一个域名的目的是便于记忆和沟通的一组服务器的地址(网站,电子邮件,FTP等)。

这个博客使用的域名为(blog.yanximin.site)是从阿里云上直接购买得到. 第一年四块钱(很实惠有没有), 但是今年就已经变成了40块钱(坑...).

VPS

VPS(Virtual Private Server 虚拟专用服务器)技术,将一台服务器分割成多个虚拟专享服务器的优质服务。实现VPS的技术分为容器[1] 技术,和虚拟化技术[2] 。在容器或虚拟机中,每个VPS都可分配独立公网IP地址、独立操作系统、实现不同VPS间磁盘空间、内存、CPU资源、进程和系统配置的隔离,为用户和应用程序模拟出“独占”使用计算资源的体验。VPS可以像独立服务器一样,重装操作系统,安装程序,单独重启服务器。VPS为使用者提供了管理配置的自由,可用于企业虚拟化,也可以用于IDC资源租用。

VPS服务器是在搬瓦工上购买,一个月十块钱(1000G流量,10G硬盘). 当服务器的同时,还能顺便FQ,可以说相当划算. VPS上直接使用Bandwagon提供的镜像,安装了CentOS 6. 顺便说一下,他们家的VPS提供了安装ShawdowSocks的脚本,一键安装,十分方便.

博客搭建

Hexo

本博客使用Hexo框架搭建的.除此之外,使用了indigo 作为网站的前端模板.

Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。

而inidigo模板主要有以下的特色

  1. 仅支持 IE10+ 等现代浏览器。
  2. 去 jQuery,更轻。相信现代浏览器的原生兼容性。
  3. 使用 Less 作为 css 预处理器,需要安装 hexo-renderer-less
  4. 添加了英文字体支持 Roboto。
  5. 添加了一些波纹效果。By Waves
  6. 无前端依赖的分享实现。
  7. 基于静态数据的站内搜索,无第三方侵入。
  8. 支持文章打赏。

Nginx

目前,网站通过Hexo生成静态页面,部署在Nginx上.(之前部署在Apache上面,但是存在着一些性能和权限的问题).

使用如下的脚本在Cent OS上安装Nginx

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#安装依赖环境
yum install -y patch openssl make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils
#安装PCRE
wget http://downloads.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz
tar zxf pcre-8.36.tar.gz
cd pcre-8.36/
./configure && make && make install
cd ../
#安装NGINX
wget http://nginx.org/download/nginx-1.6.3.tar.gz
tar zxf nginx-1.6.3.tar.gz
cd nginx-1.6.3/
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-http_spdy_module
make && make install
cd ../

ln -s /usr/local/lib/libpcre.so.1 /lib
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
rm -f /usr/local/nginx/conf/nginx.conf
mkdir -p /home/wwwroot/default
chmod +w /home/wwwroot/default
mkdir -p /home/wwwlogs
chmod 777 /home/wwwlogs
chown -R nobody:nobody /home/wwwroot/default

wget -c http://soft.vpser.net/lnmp/ext/init.d.nginx
cp init.d.nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --level 345 nginx on
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables-save
ldconfig
wget -c http://redbook.qiniudn.com/nginx.conf
mv nginx.conf /usr/local/nginx/conf/
/etc/init.d/nginx start

执行完上述脚本之后,还得修改/usr/local/nginx/conf/nginx.conf文件,修改结果如下:

user  root;

worker_processes auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid   /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 51200;

events
        {
                use epoll;
                worker_connections 51200;
                multi_accept on;
        }

http
        {
                include       mime.types;
                default_type  application/octet-stream;

                server_names_hash_bucket_size 128;
                client_header_buffer_size 32k;
                large_client_header_buffers 4 32k;
                client_max_body_size 50m;

                sendfile on;
                tcp_nopush     on;

                keepalive_timeout 60;

                tcp_nodelay on;

                gzip             on;
                gzip_comp_level  4;
                gzip_min_length  1k;
                gzip_buffers     4 16k;
                gzip_proxied     any;
                gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

                server_tokens off;

                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
                fastcgi_buffer_size 64k;
                fastcgi_buffers 4 64k;
                fastcgi_busy_buffers_size 128k;
                fastcgi_temp_file_write_size 256k;

                proxy_connect_timeout      5;
                proxy_read_timeout         60;
                proxy_send_timeout         5;
                proxy_buffer_size          16k;
                proxy_buffers              4 64k;
                proxy_busy_buffers_size    128k;
                proxy_temp_file_write_size 128k;

                 log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';

server
        {
                listen 80 default;
                #listen [::]:80 default ipv6only=on;
                server_name since1989.org geek.wasai.org;
                index index.html index.htm index.php;
                root  /root/hexo/public;

                #error_page   404   /404.html;
                location ~ [^/]\.php(/|$)
                        {
                                # comment try_files $uri =404; to enable pathinfo
                                try_files $uri =404;
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fastcgi.conf;
                                #include pathinfo.conf;
                        }

                location /nginx_status {
                        stub_status on;
                        access_log   off;
                }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                access_log  /home/wwwlogs/access.log  access;
        }
include vhost/*.conf;
}

重启Nginx之后,我们的博客服务就可以完美地运行了

猜你喜欢

转载自www.cnblogs.com/yanximin/p/10982165.html