Nginx的安装
- 下载 下载对应的nginx包,推荐使用稳定版本。
- 将包传至服务器
- 安装依赖环境
- 安装依赖环境
- 安装gcc环境
yum install gcc-c++- 安装PCRE库,用于解析正则表达式
yum install -y pcre pcre-devel- zlib压缩和解压缩依赖
yum install -y zlib zlib-devel- SSL 安全的加密的套接字协议层,用于HTTP安全传输,也就是https
yum install -y openssl openssl-devel - 解压安装包,需要注意,解压后得到的是源码,源码需要编译后才能安装
tar -zxvf nginx-1.16.1.tar.gz
- 编译之前,先创建nginx临时目录,如果不创建,在启动nginx的过程中会报错
mkdir /var/temp/nginx -p
- 在nginx目录,输入如下命令进行配置,目的是为了创建makefile文件
./configure \
--prefix=/usr \
--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/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--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 \
--with-pcre
MakeFile详解
| 命令 | 解释 |
|---|---|
| --prefix | 指定nginx安装目录 |
| --pid-path | 指向nginx的pid |
| --lock-path | 锁定安装文件,防止被恶意篡改或误操作 |
| --error-log | 错误日志 |
| --http-log-path | http日志 |
| --with-pcre | 启用pcre库 |
| --with-http_gzip_static_module | 启用gzip模块,在线实时压缩输出数据流 |
| --http-client-body-temp-path | 设定客户端请求的临时目录 |
| --http-proxy-temp-path | 设定http代理临时目录 |
| --http-fastcgi-temp-path | 设定fastcgi代理临时目录 |
| --http-uwsgi-temp-path | 设定uwsgi代理临时目录 |
| --http-scgi-temp-path | 设定scgi代理临时目录 |
- make编译
make
- 安装
make install
- 进入sbin目录进行启停操作
./nginx 启动
./nginx -s stop 停止
./nginx -s reload 重启