ubuntu20 编译nginx

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

隐藏版本号
在我们编译安装前我们可以隐藏Nginx软件名称以及版本号如下:
vim src/core/nginx.h
#define NGINX_VERSION "2.0.1"
#define NGINX_VER "xxxx/" NGINX_VERSION

修改HTTP头信息中的connection字段,防止回显具体版本号
vim src/http/ngx_http_header_filter_module.c
49行 :static u_char ngx_http_server_string[] = "Server: xxxx" CRLF;

有时候我们页面程序出现错误,Nginx会代我们返回相应的错误代码,回显的时候,会带上nginx和版本号,我们把他隐藏起来
vim src/http/ngx_http_special_response.c
36行 "<hr><center>xxxx</center>" CRLF


apt install openssl libssl-dev
apt install zlib1g-dev
apt install libpcre3 libpcre3-dev

./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module

make
make install

添加为系统服务

vi /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

常用命令
systemctl enable nginx
systemctl daemon-reload
systemctl status nginx
systemctl start nginx
systemctl stop nginx

posted @   boybai  阅读(7)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示