cenots7编译安装nginx

1、进入官网找到一个稳定版本(建议:一年之前的稳定版本),官网提供一下三个版本

 Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
   Stable version:最新稳定版,生产环境上建议使用的版本
   Legacy versions:遗留的老版本的稳定版

  这里我选择nginx-1.12.2这个版本进行安装 下载地址(http://nginx.org/download/nginx-1.12.2.tar.gz)

2、下载、解压缩

wget http://nginx.org/download/nginx-1.12.2.tar.gz

tar zxvf
nginx-1.12.2.tar.gz

cd nginx-1.12.2

3、nginx编译

#为nginx添加用户
groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M #-g代表所属用户组 -s /sbin/nologin 表示用户不需要登录 -M表示不需要为用户创建目录

  

 

 具体参数参考:http://nginx.org/en/docs/configure.html

 

 

  

./configure --prefix=/www/nginx-1.12.2 --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx
--with-http_ssl_module  如果网站需要使用HTTPS协议,需要编译此模块
--with-http_stub_status_module nginx监控模块
--user=nginx     nginx所使用的用户
--group=nginx   nginx所使用的用户组

 

遇到的问题:

./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= option.

 

根据提示确实PCRE这个包,直接yum安装即可 (我比较喜欢使用阿里云的yum源,可以参考http://mirrors.aliyun.com)

 

 yum install pcre pcre-devel

  

重新运行编译

 

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl= option.

  

提示缺少openssl库,继续yum安装

yum install openssl openssl-devel

 

 

重新编译安装

 cenots7编译安装nginx_第1张图片

这里表示已经配置通过。

执行编译

make                     #这里当然也可以直接make & make install

 

 

 make时间会稍微长一点,根据机器性能不同,时间也会有所不同

 

cenots7编译安装nginx_第2张图片

编译完成

 

开始安装:

make install

 

 

 cenots7编译安装nginx_第3张图片

make install 基本都是在复制文件和目录,所以速度比较快

 

 为了方便管理建立nginx得软连接

ln -s /www/nginx-1.12.2/ /www/nginx

 

 

启动nginx

/www/nginx/sbin/nginx

 如果出现下图表示端口被占用了

cenots7编译安装nginx_第4张图片

 

 

cenots7编译安装nginx_第5张图片

访问localhost提示如下界面就表示nginx已经安装完成了。

如果是远程访问,这里需要在防火墙中开放80端口

 

转载于:https://www.cnblogs.com/smala/p/9895297.html

你可能感兴趣的:(运维)