最新消息:

linux系列(centos、debian等等)系统下编译使用nginx

VPS运维 hostloc 35浏览 0评论

linux系列(centos、debian等等)系统下编译使用nginx-1

主机饭提醒各位大佬,VPS内存很小,或者是网心云之类的嵌入式设备下编译时,建议一行一行复制执行命令,多行复制执行虽会自动分段,但仍然可能会导致vps假死(可能是由于网络等众多原因)。

安装配置nginx或模块需要的编译环境。

ububtu/debian相关系统安装编译环境

apt-get -y install build-essential libtool

redhat/centos相关系统安装编译环境

yum -y install automake autoconf libtool make gcc gcc-c++

常用的nginx模块

以下模块根据需要选用,并修改对应的nginx配置。

新建nginx相关源码存放目录

用来存放存放各种源码,防止太乱的同时便于日后重复编译。

mkdir /root/nginx/

下载pcre(url重写模块)源码并预配置

pcre url重写模块官网:http://www.pcre.org/

wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz(20170503最新版)

wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.zip(20160910最新版)

wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz

unzip pcre*

tar zxvf pcre*

cd pcre*

./configure

下载zlib(gzip压缩模块)源码并预配置

zlib gzip压缩模块官网:http://www.zlib.net/

20170106检查官方于January 2, 2017更新zlib 1.2.10

20160910检查已经最新,最近版本更新时间:April 28, 2013

wget http://www.zlib.net/zlib-1.2.11.tar.gz

wget http://www.zlib.net/zlib1210.zip

wget http://zlib.net/zlib-1.2.8.tar.gz

unzip zlib*

tar zxvf zlib*

cd zlib*

./configure

下载openssl ssl模块源码

openssl ssl模块官网:http://www.openssl.org/

20170106检查更新

20160910更新openssl-1.0.2h

wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz

wget https://www.openssl.org/source/openssl-1.0.2j.tar.gz

wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz

wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz

wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz

tar zxvf openssl*

下载ngx_http_substitutions_filter_module(nginx反向代理替换模块)源码

ngx_http_substitutions_filter_module反向代理替换模块作者github:

https://github.com/yaoweibin/ngx_http_substitutions_filter_module

–no-check-certificate 是指wget不检查网站证书的意思。

20160910更新

wget https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.zip –no-check-certificate

apt-get install unzip -y

unzip master*

mv ngx_http_substitutions_filter_module-master ngx_http_substitutions_filter_module

然后会看到ngx_http_substitutions_filter_module目录,留作后用。

下载ngx_cache_purge-2.3缓存模块源码

ngx_cache_purge-2.3缓存模块首页:http://labs.frickle.com/nginx_ngx_cache_purge

20160910更新

wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz

tar -zxvf ngx_cache_purge*

下载云锁(nginx安全防护)模块源码

cd /root/nginx

wget https://codeload.github.com/yunsuo-open/nginx-plugin/zip/master -O nginx-yunsuo.zip

安装云锁服务端

wget https://download.yunsuo.com.cn/v3/yunsuo_agent_64bit.tar.gz && tar xvzf yunsuo_agent_64bit.tar.gz && chmod +x yunsuo_install/install && yunsuo_install/install

 

编译安装nginx

下载nginx主程序源码

nginx官网:http://nginx.org/

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

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

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

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

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

tar zxvf nginx*

cd nginx*

./configure –user=zhttpd –group=zhttpd –prefix=/etc/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-client-body-temp-path=/var/lib/nginx/body –http-fastcgi-temp-path=/var/lib/nginx/fastcgi –http-log-path=/var/log/nginx/access.log –http-proxy-temp-path=/var/lib/nginx/proxy –http-scgi-temp-path=/var/lib/nginx/scgi –http-uwsgi-temp-path=/var/lib/nginx/uwsgi –lock-path=/var/lock/nginx.lock –pid-path=/var/run/nginx.pid –with-http_ssl_module –with-http_v2_module –with-pcre=/root/nginx/pcre-8.40/ –with-zlib=/root/nginx/zlib-1.2.11 –with-openssl=/root/nginx/openssl-1.0.2k –add-module=/root/nginx/ngx_http_substitutions_filter_module/

 

 

./configure –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –modules-path=/usr/lib/nginx/modules –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-file-aio –with-threads –with-ipv6 –with-http_addition_module –with-http_auth_request_module –with-http_dav_module –with-http_flv_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_mp4_module –with-http_random_index_module –with-http_realip_module –with-http_secure_link_module –with-http_slice_module –with-http_ssl_module –with-http_stub_status_module –with-http_sub_module –with-http_v2_module –with-mail –with-mail_ssl_module –with-stream –with-stream_ssl_module –with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -fPIC’ –with-ld-opt=’-Wl,-z,relro -Wl,-z,now -pie’ –with-pcre=/root/nginx/pcre-8.40/ –with-zlib=/root/nginx/zlib-1.2.11 –add-module=/root/nginx/ngx_http_substitutions_filter_module/ –with-openssl=/root/nginx/openssl-1.0.2k –add-module=/root/nginx/nginx-yunsuo

 

 

–add-module=/root/nginx/nginx-yunsuo

make && make install

版本低于1.95请将把–with-http_v2_module换成–with-http_spdy_module之后重新编译通过…详情见下面)

–with-pcre=/root/nginx/pcre-8.36/ 指的是pcre-8.36 的源码路径。

–with-zlib=/root/nginx/zlib-1.2.8/   指的是zlib-1.2.8 的源码路径。

–with-openssl=/root/nginx/openssl-1.0.1k 指的是openssl-1.0.1k 的源码路径。

–add-module=/root/nginx/ngx_http_substitutions_filter_module/ 指的是ngx_http_substitutions_filter_module的源码路径。

备份nginx并升级。

如果原本已经有 nginx, 只执行 make 即可,make install 会覆盖掉你的 nginx.conf

nginx1.8.0以上版本到nginx目录下objs/Makefile文件首行文件后增加-DHIGHERTHAN8,如果是tengine无需修改,如果是旧版本nginx见yunsuo官网:http://help.yunsuo.com.cn/instruction/Nginx/install.html

增加后的样子

CC = cc
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -DHIGHERTHAN8
CPP = cc -E
LINK = $(CC)

建立nginx 用户和组,id www 是确定www账户的uid和gid及所属分组用户名等是否正确

groupadd -r zhttpd

useradd -s /sbin/nologin -g zhttpd -r zhttpd

id zhttpd

新建/var/lib/nginx目录.

否则会报nginx: [emerg] mkdir() “/var/lib/nginx/body” failed (2: No such file or directory)错误

mkdir /var/lib/nginx

复制编译好的nginx

cp ./objs/nginx /usr/sbin/

启动nginx

/usr/sbin/nginx

备份nginx二进制文件(新安装请直接跳过这步)

cp /usr/sbin/nginx /usr/sbin/nginx.bak

停止nginx(小站停几秒钟无所谓,大站估计也不用看教程。)

service nginx stop

升级nginx二进制文件:

cp ./objs/nginx /usr/sbin/

宝塔安装自定义模块

https://www.bt.cn/bbs/thread-16118-1-1.html

修改nginx安装脚本增加编译的模块

/www/server/panel/install/nginx.sh

–add-module=/root/nginx/ngx_http_substitutions_filter_module/ –add-module=/root/nginx/nginx-yunsuo

执行脚本开始编译安装nginx

如果执行提示没权限之类的,先关闭宝塔、云锁之类的系统加固功能。

1.15代表版本号

sh /www/server/panel/install/nginx.sh install 1.15

nginx添加以下信息

proxy_cache_path /home/cache/path levels=1:2 keys_zone=c_1:18m inactive=7d max_size=1g;#5m为内存占用,1g为最大硬盘占用,c_1为缓存区名字,如果修改则下文的配置亦要相应修改。
include /www/server/panel/vhost/nginx/*.conf;
include /www/server/panel/vhost/nginx/google/*.conf;
include /www/server/panel/vhost/nginx/other/*.conf;

 

tar: Old option `f’ requires an argument.

提示了就加-或者删掉-

tar -zxvf ngx_cache_purge*

转载请注明:主机饭 » linux系列(centos、debian等等)系统下编译使用nginx

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址