参考:
http://www.cnblogs.com/mfc-itblog/p/5718655.html
1、线上下载 nginx
wget http://nginx.org/download/nginx-1.11.9.tar.gz
2、解压
tar zxvf nginx-1.2.6.tar.gz
3、进入文件目录
cd nginx-1.2.6/
4、编译 文件
安装目录:/usr/local/nginx/(自选)
./configure --user=www --group=www --prefix=/usr/local/nginx \--with-http_stub_status_module --with-http_ssl_module
在nginx发布的版本中,除了http和mail模块之外,还有一些其他模块在默认安装时并没有被安装可通过以下配置来启用相应的选项(http://www.cnblogs.com/HKUI/p/5225895.html )
--prefix : Nginx安装的根路径,所有其它路径都要依赖该选项
--with-http_stub_status_module :
这个模块可以取得一些nginx的运行状态,如果是工业状况,可以直接取消,
输出的状态信息科使用RRDtool或类似的工具绘制成图
--with-http_ssl_module :
如果需要对流量加密.可使用此选项,在urls中开始部分将会是https(需要openssl库)
① 直接执行,出现错误 1
错误代码
checking for PCRE library … not found checking for PCRE library in /usr/local/ … not found checking for PCRE library in /usr/include/pcre/ … not found checking for PCRE library in /usr/pkg/ … not found checking for PCRE library in /opt/local/ … not found ./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(让 Ngnix 支持 Rewrite 功能。)
下载安装 prec 以及依赖包
yum install pcre-devel
② 再次执行 Nginx 编译的代码出现错误 2
提示安装 openssl 组件
直接下载安装 openssl
yum install openssl openssl-devel
./configure --with-http_ssl_module --with-ipv6
Make
Make install
之后再次编译Nginx 的编译
5、安装
make
make install
6、Nginx安装完毕,然后使用命令:
/usr/local/nginx/sbin/nginx -t
测试OK,代表nginx安装成功
7、启动 Nginx 服务
/usr/local/nginx/sbin/nginx
可以通过访问http://ip/看到nginx默认页面。
8、端口占用时修改 nginx.conf 配置文件
当然以上只是一种安装方式,可以以其他方式安装