1. 下载nginx依赖文件
1). openssl-1.0.2k
2). pcre-8.40
3). zlib-1.2.11
将依赖文件解压至/usr/local/ 路径下
2. 解压nginx源码包
3. 进入nginx源码文件夹 中。 执行:
./configure --prefix=/usr/local/nginx-1.10.1 --with-zlib=/usr/local/zlib-1.2.8/
--with-pcre=/usr/local/pcre-8.40/ --with-openssl=/usr/local/openssl-1.0.2k/ --with-mail --with-mail_ssl_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_realip_module --with-http_ssl_module
4. make
5. make install
6. 将nginx 命令设置成全局变量:
update-alternatives --install /usr/bin/nginx nginx /usr/local/nginx/sbin/nginx 7777
7.启动nginx : nginx
如果没有加入全局变量,则需要进入nginx安装文件夹下的 sbin 文件夹。 然后执行nginx 命令.
8.停止nginx :nginx -s stop
zlib-1.2.11.tar.gz,pcre-8.40.tar.gz,openssl-1.0.2k.tar.gz
#NGINX编译安装不需要单独编译每个依赖包,记住解包路径即可,这里使用/usr/local/
nginx-1.10.1.tar.gz:
./configure --prefix=/usr/local/nginx-1.10.1
--with-zlib=/usr/local/zlib-1.2.11
--with-pcre=/usr/local/pcre-8.39
--with-openssl=/usr/local/openssl-1.0.2k
#使用对应模块用with,禁用为without,根据实际引入模块([链接]模块介绍),蓝色为个人常用模块
# 配置邮件模块:
--with-mail 该选项用于启用Mail模块,该模块默认没有被激活
--with-mail_ssl_module 为了代理任何一种类型的使用SSL/TLS的Mail,激活该模块
--without-mail_pop3_module 在启用Mail模块后,单独地禁用pop3模块
--without-mail_imap_module 在启用Mail模块后,单独地禁用imap模块
--without-mail_smtp_module 在启用Mail模块后,单独地禁用smtp模块
#完全禁用http模块:--without--http
--with-http_ssl_module 如果需要对流量进行加密,可以使用该选项,在URLs中开始部分将会是https(需要OpenSSL库)
--with-http_realip_module 如果你的Nginx在七层负载均衡器或者是其他设备之后,它们将http头中的客户端IP地址传递,那么你将会需要启用这个模块。在多个客户处于一个IP地址的情况下使用
--with-http_addition_module 这个模块作为输出过滤器,使你能够在请求经过一个location前或者后时在该location本身添加内容
--with-http_xslt_module 该模块用于处理XML响应转换,基于一个或者多个XSLT格式(需要libxml2和libxslt库)
--with-http_image_filter_module 该模块被作为图像过滤器使用,在将图形投递到客户之前进行处理(需要libgd库)
--with-http_geoip_module 使用该模块,能够设置各种变量以便在配置文件中区段使用,基于地理位置查找客户端IP地址(需要MaxMfind GeoIP库和相应的预编译数据库文件)
--with-http_sub_module 该模块实现了替代过滤,在响应中用一个字符串替代另一个字符串
--with-http_dav_module 启用这个模块将激活使用WebDAV的配置指令。注意:这个模块也只在有需要使用的基础上启用,如果配置不正确,它将带来安全问题。
--with-http_flv_module 如果需要提供Flash流媒体视频文件,那么该模块将会提供伪流媒体
--with-http_mp4_module 这个模块支持H.264/AAC文件伪流媒体
--with-http_gzip_static_module 当被调用的资源没有.gz结尾格式的文件时,如果想支持发送预压缩版本的静态文件,那么使用该模块
--with-http_gunzip_module 对应不支持gzip编码的客户,该模块用于为客户解压缩预压缩内容
--with-http_random_index_module 如果你想提供从一个目录中随机选择文件的索引文件,那么这个模块需要被激活
--with-http_secure_link_module 该模块提供了一个机制,它会将一个哈希值链接到一个URL中,因此,只有那些使用正确的密码能够计算链接
--with-http_stub_status_module 启用这个模块后会收集Nginx自身的状态信息。输出的状态信息可以使用RRDtool或类似的东西来绘制成图
--with-stream 用于一般的TCP代理和负载均衡
编译nginx后,如果需要添加新的参数,又不想重新安装,可以使用以下方法:
①执行nginx -V出现nginx版本号和之前的编译参数。
②使用对应的源码包然后用原有的编译参数再添加新的需要的编译参数执行./configure,然后make。
③不出现报错的话再源码包的objs目录下会出现加入新参数的nginx,备份原来的nginx然后覆盖。
④使用nginx -t测试新版本是否符合conf语法
ubuntu14.04上源码安装openssl1.0.2k
openssl-1.0.2k 编译安装
ubuntu14.04上源码安装openssl1.0.2k
- 卸载自带openssl
apt-get remove openssl
- 解压文件
tar -xzf openssl-1.0.2k.tar.gz
- 配置
./config shared --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
shared 表示生成动态库
- 编译
make
-
安装
sudo make install
-
设置环境变量
sudo gedit ~/.bashrc
在最后一行添加export PATH=$PATH:/usr/local/openssl/bin
保存退出,使用source ~/.bashrc
使其立即生效。 -
创建符号链接(这部可做可不做,看你的需求)
#ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
#ln -s /usr/local/ssl/openinclude/openssl /usr/include/openssl -
刷新动态库配置
#vim /etc/ld.so.conf