ror-tutorial-v2-notes

VPS基本设置

1. 基本情况说明

本VPS操作系统为CentOS7.

[root@vps1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core)

首先,更新系统:

[root@vps1 ~]# yum update

2. 配置shadowsock服务

无他,仅仅为了翻墙。

[root@vps1 ~]# yum install python-setuptools && easy_install pip

具体安装及配置方法参考shadowsocks.

3.添加普通用户

[root@vps1 ~]# /usr/sbin/useradd fangpeng
[root@vps1 ~]# passwd fangpeng

并配置密码,后续大部分操作将以普通用户进行。

4. 安装git

[root@vps1 ~]# yum install git

5. 安装基本的编译工具

[root@vps1 ~]# yum groupinstall "Development tools"

6. 安装Openresty

[fangpeng@vps1 ~]$ mkdir project
[fangpeng@vps1 ~]$ cd project/                          
[fangpeng@vps1 project]$ wget https://github.com/openresty/ngx_openresty/archive/v1.7.10.1.tar.gz -O ngx_openresty-1.7.1
0.1.tar.gz
[fangpeng@vps1 project]$ tar xvfz ngx_openresty-1.7.10.1.tar.gz
[fangpeng@vps1 project]$ cd ngx_openresty-1.7.10.1
[fangpeng@vps1 ngx_openresty-1.7.10.1]$ make
[fangpeng@vps1 ngx_openresty-1.7.10.1]$ cd ngx_openresty-1.7.10.1
[fangpeng@vps1 ngx_openresty-1.7.10.1]$ ./configure

此时报错误

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

因此,先安装pcre库:

[root@vps1 ~]# yum install pcre-devel

然后,继续安装openresty:

[fangpeng@vps1 ngx_openresty-1.7.10.1]$ ./configure

报错:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

因此,继续安装openssl库:

[root@vps1 ~]# yum install openssl-devel

继续安装openresty:

[fangpeng@vps1 ngx_openresty-1.7.10.1]$ ./configure
[fangpeng@vps1 ngx_openresty-1.7.10.1]$ make
[fangpeng@vps1 ngx_openresty-1.7.10.1]$ su
[root@vps1 ngx_openresty-1.7.10.1]# make install

7. 配置域名解析到该VPS

我有一个域名pureage.info,DNS解析用的是DNSPOD,但该域名正在使用中,因此新建一个子域名用于本笔记的演示。该子域名为:rails.pureage.info。在DNSPOD的管理后台,添加一条rails的A记录,内容是VPS的IP。

在VPS的nginx配置文件里加一条rails.pureage.info的vhost.

[root@vps1 ngx_openresty-1.7.10.1]# vim /usr/local/openresty/nginx/conf/nginx.conf

将默认的server_name由localhost改为rails.pureage.info

启动Nginx:

[root@vps1 ngx_openresty-1.7.10.1]# /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf

此时,在浏览器中访问http://rails.pureage.info, 即可看到Nginx的默认欢迎页面,如下图所示: