阿里雲VPS搭建Hexo博客


最近買了一個阿里雲服務器,准備寫自己的網站,和將自己的作品放在上面;開始的時候,感覺就一個服務器應該很簡單,但是從申請域名到備案,再到服務器搭建,沒想到一波三折;閑話不多說,只是記錄我在搭建時,最簡單的方法;

環境

主機:Centos6.8
服務器:nginx,nodejs
數據庫:mongoDB,mysql
其他:git,vsftp

安裝vsftp

vsftp是一個基於Linux系統上的FTP服務器軟件,至於它的作用就不用多說了吧,是用來傳輸文件的;下面是安裝步驟:

查看是否已安裝vsftp

rpm -qa | grep vsftpd

回車;如果出現如下提示,代表您已經安裝過vsftp,可以跳過該步驟了;

如果什么都沒有,那說明您還沒有安裝,接着下面的步驟:
安裝vsftp並設置開機自啟動

yum -y install vsftpd
chkconfig vsftpd on

編輯其配置文件

vi  /etc/vsftpd/vsftpd.conf

找到如下配置,並更改

anonymous_enable=NO
ascii_upload_enable=YES
ascii_download_enable=YES
chroot_local_user=YES

添加FTP賬號,在客戶端遠程請求,傳輸文件:

useradd -s /sbin/nologin -d username  //添加用戶名
passwd  username   //設置密碼

關閉防火牆,重啟vsftpd

setenforce  0
service  vsftpd restart

當您將上面的步驟全部實現后,可能還不能傳輸文件,那可能因為文您的文件夾沒有更改的權限:

chmod -R 777 您的文件夾名

安裝ngnix

我這里安裝ngnix是按照阿里雲提供的方法安裝的,地址是 https://help.aliyun.com/document_detail/50700.html?spm=5176.doc50775.6.655.Epe5kw;

添加運行ngnix服務進程的用戶

groupadd -r nginx
useradd  -r -g nginx nginx

下載源碼包解壓編譯

wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
yum groupinstall "Development tools"
yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
cd /usr/local/src/nginx-1.10.2

./configure \
  --prefix=/usr/local/nginx \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx.pid \
  --lock-path=/var/run/nginx.lock \
  --http-client-body-temp-path=/var/tmp/nginx/client \
  --http-proxy-temp-path=/var/tmp/nginx/proxy \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  --http-scgi-temp-path=/var/tmp/nginx/scgi \
  --user=nginx \
  --group=nginx \
  --with-pcre \
  --with-http_v2_module \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_addition_module \
  --with-http_sub_module \
  --with-http_dav_module \
  --with-http_flv_module \
  --with-http_mp4_module \
  --with-http_gunzip_module \
  --with-http_gzip_static_module \
  --with-http_random_index_module \
  --with-http_secure_link_module \
  --with-http_stub_status_module \
  --with-http_auth_request_module \
  --with-mail \
  --with-mail_ssl_module \
  --with-file-aio \
  --with-ipv6 \
  --with-http_v2_module \
  --with-threads \
  --with-stream \
  --with-stream_ssl_module


make && make install

添加至服務管理列表,設置開機自啟。

chkconfig --add nginx
chkconfig  nginx on

安裝git

安裝依賴的庫

 yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

下載git

wget  https://github.com/git/git/archive/v2.12.2.tar.gz
tar -zvxf git-2.12.2.gz -C /usr/local/src
cd /usr/local/src/git-2.12.2
./configure --prefix=/usr/local/git
make 
make  install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile
source  /etc/profile

安裝node

我這里是使用NVM安裝node,是Node.js的版本管理軟件,使用戶可以輕松在Node.js各個版本間進行切換。

直接使用git將源碼克隆到本地

git clone https://github.com/cnpm/nvm.git /usr/local/node/.nvm && cd /usr/local/node/.nvm && git checkout `git describe --abbrev=0 --tags`

激活NVM

echo ". /usr/local/node/.nvm/nvm.sh" >> /etc/profile
source /etc/profile

列出Node.js的所有版本

nvm list-remote

安裝Node.js版本

nvm install v6.10.2

查看已安裝Node.js版本,當前使用的版本為v6.9.5。

[root@iZuf62didsxigy36d6kjtrZ .nvm]# nvm ls

ngnix反向代理node項目

vi /etc/nginx/nginx.conf

添加如下配置:

server {
  listen 80;
    server_name www.xxx.com xxx.com;
    access_log /var/log/nginx/test.log;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host  $http_host;
        proxy_set_header X-Nginx-Proxy true;
        proxy_set_header Connection "";
        proxy_pass      http://127.0.0.1:3000;
      }
}    

至此,基本上環境安裝完成,不足之處,請各位多多包涵。至於mysql和mongoDB的安裝,請參照以下地址去安裝:

mysql:https://help.aliyun.com/document_detail/50700.html?spm=5176.doc50775.6.655.Epe5kw

mongoDB: http://www.runoob.com/mongodb/mongodb-linux-install.html

原文: http://blog.hawkzz.com/2017/04/19/阿里雲VPS搭建Hexo博客/  作者: hawk_zz


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM