第一步 Nginx 安装依赖的库:
$ yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel gd gd-devel
说明:
必须项: gcc gcc-c++ ———— 编译用的;
非必需:(可根据实际需求来配置)
pcre pcre-deve ———— rewrite模块需要;
zlib zlib-devel ———— gzip模块需要;
openssl openssl-devel ———— ssl 功能需要;
gd gd-devel ———— 图片处理模块需要;
第二步 安装 nginx
下载地址:http://nginx.org/en/download.html
$ cd /usr/local/src
$ wget http://nginx.org/download/nginx-1.14.2.tar.gz
解压:
$ tar zxvf nginx-1.14.2.tar.gz
解压完后:
进入到nginx-1.14.2 进行配置需要编译的模块:
$ cd nginx-1.14.2
$ ./configure --prefix=/usr/local/application/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-pcre --with-debug --with-http_gzip_static_module --with-http_image_filter_module
说明:
必须项:
-
--prefix=/usr/local/application/nginx #编译后的文件位置
非必需:
-
--with-http_ssl_module #ssl模块
-
--with-http_flv_module #flv模块
-
--with-http_stub_status_module #nginx运行状态监听模块
-
--with-http_gzip_static_module #gzip模块
-
--with-pcre #rewrite模块**
-
--with-http_image_filter_module #图片处理模块
-
--with-debug #debug模块
编译没有任何异常时make && make install
至此nginx 安装成功!!!
启动Nginx:
$ cd /usr/local/applition/nginx
$ ./sbin/nginx
如果访问不了,请关闭防火墙或者开放80端口
$ systemctl stop firewalld.service # 关闭防火墙
$ systemctl disable firewalld.service # 禁止开机自启动防火墙
注:
安装问题:
如果编译失败提示类似如下信息:
说明需要安装 gd 库,一般在安装库时会同时安装 gd-devel(开发版本库,便于定位错误)
$ yum install -y gd gd-devel
此时还需要删除刚解压的nginx文件包,然后重新解压,再编译就OK了。