Nginx是一个模块化的Web服务器,但默认安装可能包含一些你不需要的模块。以下是移除不必要Nginx模块的方法:
最彻底的方法是重新编译Nginx时排除不需要的模块:
首先查看当前Nginx版本和编译参数:
nginx -V
下载对应版本的Nginx源代码:
wget http://nginx.org/download/nginx-{version}.tar.gz
tar -xzvf nginx-{version}.tar.gz
cd nginx-{version}
配置编译参数,使用--without-{module_name}
排除不需要的模块:
./configure --prefix=/usr/local/nginx \
--without-http_gzip_module \
--without-http_rewrite_module \
# 其他你需要的参数...
编译并安装:
make
sudo make install
如果使用动态模块,可以简单地不加载不需要的模块:
在nginx.conf中注释掉不需要的模块加载指令:
# load_module modules/ngx_http_geoip_module.so;
重启Nginx:
sudo systemctl restart nginx
以下是一些通常可以安全移除的模块(根据你的需求):
--without-http_gzip_module
- 如果不需gzip压缩--without-http_rewrite_module
- 如果不需URL重写--without-http_proxy_module
- 如果不需代理功能--without-http_fastcgi_module
- 如果不需PHP-FPM支持--without-mail_pop3_module
- 如果不需邮件代理--without-mail_imap_module
- 如果不需邮件代理--without-mail_smtp_module
- 如果不需邮件代理安装后验证模块是否已移除:
nginx -V
输出中不应包含被移除的模块。