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 @ 2020-12-11 11:49  boybai  阅读(7)  评论(0编辑  收藏  举报