1,132   Nginx Ubuntu

因为想在Ubuntu上给Nginx添加echo-nginx-module,所以源码安装Nginx,同时添加module参数;

一,安装过程:

 

1,下载echo-nginx-module

$  wget https://github.com/openresty/echo-nginx-module/archive/master.zip
$  unzip master.zip 
$  cd echo-nginx-module-master/

2,下载Nginx

 $ wget 'http://nginx.org/download/nginx-1.9.7.tar.gz'
 $ tar -xzvf nginx-1.9.7.tar.gz
 $ cd nginx-1.9.7/

3,查看原先安装的nginx的configure参数

$ nginx -V
nginx version: nginx/1.8.1
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04) 
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed' --with-ipv6

4,在原来configure参数上添加echo-nginx-module配置–add-module=/home/chenyunhui/echo-nginx-module-master

$ cd nginx-1.9.7/
$ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed' --with-ipv6 --add-module=/home/chenyunhui/echo-nginx-module-master

$ make -j2
$ make install

 

 

5,在nginx的http的server添加以下内容

        location =/hello {
                default_type "text/plain";
                echo "hello";
        }

6,重启Nginx并测试

chenyunhui@ubuntu:/etc/nginx/sites-available$ curl -I http://localhost/hello
HTTP/1.1 200 OK
Server: nginx/1.9.7
Date: Fri, 08 Apr 2016 09:45:56 GMT
Content-Type: text/plain
Connection: keep-alive

chenyunhui@ubuntu:/etc/nginx/sites-available$ curl  http://localhost/hello
hello

 

二,遇到错误:

 

1,报错1

./configure: error: invalid option "--with-http_spdy_module"

官网解释:This module was superseded by the ngx_http_v2_module module in 1.9.5.
详细信息查看这里
解决方法:

$ ./configure --prefix=/etc/nginx  --with-http_v2_module即可

2,报错2

./configure: error: the HTTP rewrite module requires the PCRE library

缺少pcre模块,更多信息

解决方法:

$ apt-get install libpcre3 libpcre3-dev



Leave a Reply

Your email address will not be published. Required fields are marked *