前言
Nginx一款高性能反向代理服务器,而且支持负载均衡,包括权重策略,回话策略(Sticker),随机策略。
准备安装文件
以下为大家准备了安装文件,也可以自己到网上下载
下载地址:http://nginx.org/en/download.html
准备文件 | 下载地址 |
---|---|
nginx-1.8.1.tar | 链接: https://pan.baidu.com/s/1dlUjcLjemTcm7jnc0HDiwQ 提取码: typ4 |
安装Nginx所需环境
./configure(进入解压目录执行./configure,会提示所需要的依赖包,一个一个安装即可)
1
2
3
4
5
6
7[root@iZwz94664y88uf68wjzri0Z soft]# tar -xvf nginx-1.8.1.tar.gz
[root@iZwz94664y88uf68wjzri0Z soft]# cd nginx-1.8.1
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.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.安装 gcc
1
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# yum install gcc-c++
安装 pcre pcre-devel
1
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# yum install -y pcre pcre-devel
安装 zlib
1
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# yum install -y zlib zlib-devel
安装 Open SSL
1
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# yum install -y openssl openssl-devel
Nginx安装
配置
1
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# ./configure
编译安装
1
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# make && make install
配置环境变量
1
2
3
4
5
6
7[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# vim /etc/profile
# 增加以下环境配置
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
# 使之生效
[root@iZwz94664y88uf68wjzri0Z nginx-1.8.1]# source /etc/profile
Nginx启动
启动
1
2[root@iZwz94664y88uf68wjzri0Z /]# cd /usr/local/nginx/sbin
[root@iZwz94664y88uf68wjzri0Z sbin]# ./nginx检查验证
1
2
3
4[root@iZwz94664y88uf68wjzri0Z sbin]# ps -ef | grep nginx
root 23310 1 0 17:38 ? 00:00:00 nginx: master process ./nginx
nobody 23311 23310 0 17:38 ? 00:00:00 nginx: worker process
root 23319 19627 0 17:38 pts/0 00:00:00 grep --color=auto nginx关闭
1
2
3[root@iZwz94664y88uf68wjzri0Z sbin]# ./nginx -s stop
[root@iZwz94664y88uf68wjzri0Z sbin]# ps -ef | grep nginx
root 23324 19627 0 17:38 pts/0 00:00:00 grep --color=auto nginx重启
1
2
3
4
5
6
7
8[root@iZwz94664y88uf68wjzri0Z sbin]# ./nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@iZwz94664y88uf68wjzri0Z sbin]# ./nginx
[root@iZwz94664y88uf68wjzri0Z sbin]# ./nginx -s reload
[root@iZwz94664y88uf68wjzri0Z sbin]# ps -ef | grep nginx
root 23327 1 0 17:39 ? 00:00:00 nginx: master process ./nginx
nobody 23336 23327 0 17:39 ? 00:00:00 nginx: worker process
root 23342 19627 0 17:39 pts/0 00:00:00 grep --color=auto nginx检查配置文件
1
2
3
4
5
6
7[root@iZwz94664y88uf68wjzri0Z sbin]# ./nginx -t
nginx: [emerg] unexpected "}" in /usr/local/nginx/conf/nginx.conf:24
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
[root@iZwz94664y88uf68wjzri0Z sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@iZwz94664y88uf68wjzri0Z sbin]#
Nginx配置网站服务
1 | [root@iZwz94664y88uf68wjzri0Z conf]# cd /usr/local/nginx/conf |
1 | [root@iZwz94664y88uf68wjzri0Z conf]# vimextra/lishijia.conf |
总结
通过以上方式把个人博客迁移的自己的服务器,之前是通过github、coding发布的pages服务来运行的个人博客。