NGINX编译安装

一、编译安装

./configure  
--prefix=/usr  
--sbin-path=/usr/sbin/nginx  
--conf-path=/etc/nginx_1_6/nginx.conf  
--error-log-path=/var/log/nginx/error.log  
--http-log-path=/var/log/nginx/access.log  
--pid-path=/var/run/nginx/nginx.pid    
--lock-path=/var/lock/nginx.lock  
--user=nginx  
--group=nginx  
--with-http_ssl_module  
--with-http_flv_module  
--with-http_stub_status_module  
--with-http_gzip_static_module  
--http-client-body-temp-path=/var/tmp/nginx/client/  
--http-proxy-temp-path=/var/tmp/nginx/proxy/  
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/  
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi  
--http-scgi-temp-path=/var/tmp/nginx/scgi  
--with-pcre   --with-file-aio

编译过程中,会出现找不到类库的问题,先装好类库,再重复执行就好了

二、测试NGINX环境

执行以下语句

$ sudo /etc/init.d/nginx configtest

看到以下提示就说明已经可以具备了启动所有的环境

Testing nginx configuration: nginx.

我遇到的错误是这样的

在启动nginx之前还需要添加nginx用户组,否则会提示

[emerg]: getpwnam(“nginx”) failed

添加用户组

sudo adduser --system --no-create-home --disabled-password --group nginx

三、启动NGINX

启动NGINX

sudo /etc/init.d/nginx start

看到以下提示说明启动成功

Starting nginx: nginx.

四、添加新module

将需求添加的module下载好,解压

假设解压到的目录为/workspace/tar/echo-nginx-module-0.57

目前nginx不支持在动行时添加module,以下说明摘自官网

Nginx modules must be selected during compile, run-time selection of modules is not currently supported.
A full summary of the compile-time options, including optional modules, can be found in the provided configure script by running ./configure --help

通过以下命令查看当前NGINX已经安装了什么module

$ nginx -V
nginx version: nginx/1.6.2
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
TLS SNI support enabled
configure arguments: --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx_1_6/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-file-aio

开始添加新module

./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx_1_6/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-file-aio --add-module=/workspace/tar/echo-nginx-module-0.57
$ make

到此为止,新的module已经编译到了NGINX可执行文件中,但不要执行make install
保存现在系统中使用的NGINX可执行文件,手工把新编译后的文件拷过去,重启即可


五、NGINX与APACHE

两者都是WEB容器

共同点:都是通过模块化的进行组织

区别:

APACHE是动态加载模块方式,添加新模块不需要重启,只需要重新载入

NGINX是静态加载模块方式,每次添加模块需要重新编译,安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值