Nginx 部署

🎽 Nginx 是一个很强大的高性能Web和反向代理服务器

前言

环境

OS: Ubuntu-16

安装

依赖

目录结构

/opt
|– nginx-1.10.1
|– pcre-8.38
`– zlib-1.2.8

shell

以下操作均在/opt目录

1
2
3
# tar -zxvf nginx-1.10.1.tar.gz
# cd nginx-1.10.1
# ./configure

ERROR:

1
2
3
4
5
checking for OS
+ Linux 2.6.32-042stab113.21 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

缺失编译部件, 解决办法如下:

1
2
# apt-get install build-essential libtool
# ./configure

Error:

1
2
3
4
./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, 移步官网下载(顶部有链接), 我是在/opt目录中解压
: pcre 没有 2

以下操作均在/opt目录

1
2
3
# tar -jxvf pcre-8.38.tar.bz2
# cd pcre-8.38
# ./configure && make && make install

回到/opt/nginx-1.10.1目录继续进行

1
# ./configure --with-pcre=/opt/pcre-8.38

Error:

1
2
3
4
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

原因是缺失zlib,移步官网下载(顶部有链接), 同样是在/opt目录中解压

以下操作均在/opt目录

1
2
3
# tar -zxvf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure && make && make install

回到/opt/nginx-1.10.1目录继续进行

1
2
3
# ./configure --with-pcre=/opt/pcre-8.38 --with-zlib=/opt/zlib-1.2.8
# make
# make install

至此,安装结束。可查看ls /usr/local/nginx/目录
显示如下文件:
/usr/local/nginx/
image

基础命令

以下命令均在/usr/local/nginx目录下运行

1
2
3
4
5
6
7
8
# 启动
./sbin/nginx
# 检查配置
./sbin/nginx -t
# 重新加载配置
./sbin/nginx -s reload
# 查看配置文件
cat ./conf/nginx.conf

扩展

nginx.conf配置

字段详解

模块

待续ing

分享到