51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

编译安装Nginx取消debug模式

在编译nginx时,默认会以debug模式来运行,取消debug的好处是编译后的nginx更加小巧,编译更快。

1、下载nginx源码包
wget http://nginx.org/download/nginx-1.14.0.tar.gz

|---|----------------------------------------------------| | 1 | wget http://nginx.org/download/nginx-1.14.0.tar.gz |

2、解压缩后编辑auto/cc/gcc文件
vi nginx-1.14.0/auto/cc/gcc

|---|-----------------------------| | 1 | vi nginx-1.14.0/auto/cc/gcc |

删除其中两行

debug CFLAGS="$CFLAGS -g"

|-----|-----------------------------| | 1 2 | # debug CFLAGS="$CFLAGS -g" |

3、安装依赖并创建nginx启动用户
yum install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel useradd -s /bin/false -M www

|-----|-----------------------------------------------------------------------------------------------------------------| | 1 2 | yum install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel useradd -s /bin/false -M www |

4、正式开始编译nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module make make install

|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module make make install |

5、设置软链接
ln -sv /usr/local/nginx/sbin/nginx /usr/local/sbin/

|---|-----------------------------------------------------| | 1 | ln -sv /usr/local/nginx/sbin/nginx /usr/local/sbin/ |

6、设置systemctl
vi /usr/lib/systemd/system/nginx.service

|---|------------------------------------------| | 1 | vi /usr/lib/systemd/system/nginx.service |


[Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target

|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 | [Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target |

7、启动nginx并设置开机自启
systemctl start nginx systemctl enable nginx

|-----|----------------------------------------------| | 1 2 | systemctl start nginx systemctl enable nginx |

8、结语

同样的编译参数,在没有取消debug模式前,编译后的nginx大小12M,取消后nginx的大小为1000K。

赞(0)
未经允许不得转载:工具盒子 » 编译安装Nginx取消debug模式