💽编译安装
💽 编译安装(适合非root用户)
基础流程
st=>start: 1、下载、获取软件包
e=>end: 完成
2=>operation: 2、安装编译依赖环境
3=>operation: 3、解压软件包并进入目录
4=>operation: 4、配置./configure定制功能:
gzip、缓存、定制软件相关目录等
5=>operation: 5、定制配置文件:
nginx -tc /xxx/配置文件
6=>operation: 6、启动项目 :
nginx -c /xxx/配置文件
st->2
2->3->4->5->6
6->e
下载
# http://nginx.org/en/linux_packages.html#RHEL-CentOS
安装编译依赖
- PCRE库 - nginx 的正则支持
- zlib库 - nginx 压缩http的库
- openssl- ngins openssl 库
yum -y install make gcc-c++ libtool
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
基本编译配置
# 解压安装包
tar -zxvf nginx-1.12.0.tar.gz
# 进入解压目录
cd nginx-1.12.0
# 编译命令
./configure
--user=nginx \ # 专用用户
--group=nginx \ # 专用用户
--prefix=/etc/nginx \ # 默认软件的目录
--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.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module
# 编译安装
make && make install
# 创建软连接
ln -s {软件安装目录} /usr/bin/nginx
# 查看最后安装完成后的相关路径
whereis nginx
常见的编译配置
常用 | 作用 |
---|---|
--prefix=PATH | Nginx 安装的根路径,所有其他的安装路径都要依赖于该选 |
--sbin-path=PATH | 指定Nginx 二进制文件的路径。如果没有指定,那么这个路径会 依赖于 prefix 选项 |
--conf-path=PATH | 如果在命令行没有指定配置文件,那么将会通过这里指定的路径,nginx 将会去那里查找它的配置文件 |
--error-log-path=PATH | 指定错误文件的路径,nginx 将会往其中写入错误日志文件,除非有其他的配置 |
--pid-path=PATH | 指定的文件将会写入nginx master进程的pid通常卸载/var/run/目录下 |
--lock-path=PATH | 共享储存器互斥锁文件的路径 |
--user=USER | worker进程运行的用户 |
--group=GROUP | worker进程运行的用户组 |
--with-file-aio | 为FreeBSD 4.3+和linux 2.6.22+系统启用异步I/O |
--with-debug | 这个选项用于调试日志,在生产环境的系统中不推荐使用该选项 |
临时路径相关
路径相关 | 作用 |
---|---|
--error-log-path=PATH | 错误日志的默认路径 |
--http-log-path=PATH | http 访问日志的默认路径 |
--http-client-body-temp-path=PATH | 从客户端收到请求后,该选项设置的目录用于作为请求体 临时存放的目录。如果 WebDAV 模块启用,那么推荐设置 该路径为同 一文件系统上的目录作为最终的目的地 |
--http-proxy-temp-path=PATH | 在使用代理后,通过该选项设置存放临时文件路径 |
--http-fastcgi-temp-path=PATH | 设置 FastCGI 临时文件的目录 |
--http-uwsgi-temp-path=PATH | 设置 uWSG工临时文件的目录 |
--http-scgi-temp-path=PATH | 设置 SCGII临时文件的目录 |
PCRE的配置参数
PCRE的配置参数 | 作用 |
---|---|
--without-pcre | 如果确定Nginx不用解析正则表达式,那么可以使用这个参数 |
--with-pcre | 强制使用PCRE库 |
--with-pcre=DIR | 指定PCRE库的源码位置,在编译nginx时会进入该目录编译PCRE源码 |
--with-pcre-opt=OPTIONS | 编译PCRE源码是希望加入的编译选项 |
OpenSSL的配置参数
PCRE的配置参数 | 作用 |
---|---|
--with-openssl=DIR | 指定OpenSSL库的源码位置,在编译nginx时会进入该目录编译OpenSSL.如果web服务器需要使用HTTPS,那么Nginx要求必须使用OpenSSL |
--with-openssl-opt=OPTIONS | 编译OpenSSL源码时希望加入的编译选项 |
zlib的配置参数
zlib的配置参数 | 作用 |
---|---|
--with-zlib=DIR | 指定zlib库的源码位置,在编译nginx时会进入该目录编译zlib.如果需要使用gzip压缩就必须要zlib库的支持 |
--with-zlib-opt=OPTIONS | 编译zlib源码时希望加入的编译选项 |
--with-zlib-asm=CPU |