这次用一个国内开发者在GitHub上的开源项目
我的系统已经安装了最新的Nginx,现在需要下载源代码编译出自己的版本。
wget http://nginx.org/download/nginx-1.5.3.tar.gztar zxvf nginx-1.5.3.tar.gz
然后获得nginx_tcp_proxy_module的项目:
git clone https://github.com/yaoweibin/nginx_tcp_proxy_module.git现在给Nginx打补丁
cd nginx-1.5.3/root@dean-GA-MA790XT-UD4P:/usr/src/nginx-1.5.3# patch -p1 < /usr/src/nginx_tcp_proxy_module/tcp.patch patching file src/core/ngx_log.cHunk #1 succeeded at 69 (offset 3 lines).patching file src/core/ngx_log.hHunk #1 succeeded at 30 (offset 1 line).Hunk #2 succeeded at 38 (offset 1 line).patching file src/event/ngx_event_connect.hHunk #1 succeeded at 33 (offset 1 line).Hunk #2 succeeded at 44 (offset 1 line).还要安装个ssl库
apt-get install libssl-dev但是卸载掉自动安装的libstdc++6-4.7-dev, 因为我用的是gcc4.8.1
apt-get autoremove
好了,现在配置makefile,首先查看当前系统安装好的Nginx的配置选项:
nginx -Vnginx version: nginx/1.5.3built by gcc 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1) TLS SNI support enabledconfigure 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-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' --with-ipv6
然后原封不动的使用这些配置参数,但是加上最后一个
--add-module=/usr/src/nginx_tcp_proxy_module
./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-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' --with-ipv6 --add-module=/usr/src/nginx_tcp_proxy_module现在开始编译吧。
make
得到的nginx程序位于objs目录. 将nginx服务停掉,并替换之。
service nginx stopmv /usr/sbin/nginx /usr/sbin/nginx_bk/usr/src/nginx-1.5.3/objs# cp nginx /usr/sbin/service nginx startps -def | grep nginxroot 23479 1 0 23:21 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.confroot 23480 23479 0 23:21 ? 00:00:00 nginx: worker process root 23482 13006 0 23:21 pts/0 00:00:00 grep --color=auto nginx