nginx是一个高性能的反向代理服务器
正向代理代理的是客户端
反向代理代理的是服务端
安装步骤如下
1、下载安装文件 nginx-1.12.2.tar.gz 并移动到nginx文件夹下
2、依次执行如下命令 解压文件 并修改解压后的文件夹名称为 nginx112
tar -zvxf nginx-1.12.2.tar.gz
mv nginx-1.12.2 nginx112
[root@zk03 nginx]# ll
总用量 960
drwxr-xr-x. 9 1001 1001 186 1月 22 17:33 nginx112
-rw-r--r--. 1 root root 981687 2月 19 2019 nginx-1.12.2.tar.gz
3、安装 c++编译环境 及依赖环境
yum install gcc-c++
yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel perl
4、到nginx112目录下安装 nginx
[root@zk03 nginx112]# ./configure
提示 需要 PCRE library 如下:
./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.
执行 yum install -y pcre-devel 安装
5、执行 ./configure 提示 需要 zlib library
./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.
执行 yum install -y zlib-devel 安装 zlib-devel
6.再次执行 ./configure 成功。
7.执行 make &&make install 编译并安装
通过输出的日志可以看到 默认将 nginx 安装到了 /usr/local/nginx 目录 可以再 执行 configure时prefix 参数 (如 ./configure --prefix /usr/apps/nginx) 来指定安装位置
日志信息:
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
也可以通过 whereis nginx 找到安装位置 如下
[root@zk03 nginx]# whereis nginx
nginx: /usr/local/nginx
可以在该目录 下看到四个文件夹
[root@zk03 nginx112]# cd /usr/local/nginx
[root@zk03 nginx]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 1月 23 10:11 conf
drwxr-xr-x. 2 root root 40 1月 23 10:11 html
drwxr-xr-x. 2 root root 6 1月 23 10:11 logs
drwxr-xr-x. 2 root root 19 1月 23 10:11 sbin
html:服务器资源文件根目录 比如一些静态图片 放在这里
sbin:工具命令 目录
conf:配置文件目录
logs :日志文件目录
8.nginx基本操作
sbin/nginx 启动nginx
启动后 浏览器中访问主机地址(我这里是zk03)即可访问到
sbin/nginx -s stop(quit) 停止
sbin/nginx -s reload 重新加载配置
sbin/nginx -h 命令帮助
sbin/nginx -t 验证配置文件