Adjust parameters to hide the information number of Nginx software version

Reference material

[1] . learn Linux operation and maintenance from the old boy: Web Cluster practice, old boy

setup script

View native information

[root@www ~]# curl -I 127.0.0.1

server_tokens

In the http tag section of Nginx configuration file nginx.conf, add the parameter "server" tokens off

http 
{
    server_tokens off;
}

This parameter is placed in the http tag to control the display of the Web service version information in the http response header and the display of the Web service version information in the error message.

Official description of the server Ou tokens parameter

syntax: server_tokens on | off; # This is the syntax of the parameter. On is the on state and off is the off state
default: server_tokens on; # On by default
context: http, server, location # Where the server_tokens parameter can be placed

Restart and test

[root@www conf]# /application/nginx/sbin/nginx -t
[root@www conf]# /application/nginx/sbin/nginx -s reload
[root@www conf]# curl -I 127.0.0.1

Change source code, hide Nginx software name and version number

Find nginx.h file path

[root@www ~]# find / -name nginx.h

## Edit first file
[root@www ~]# vim /home/oldboy/tools/nginx-1.9.9/src/core/nginx.h
## Edit the following
#define NGINX_VERSION      "1.9.1"
#define NGINX_VER          "nginx/" NGINX_VERSION
#define NGINX_VAR          "NGINX"

## After modification, the content is as follows
#define NGINX_VERSION      "0.1"
#define NGINX_VER          "www/" NGINX_VERSION
#define NGINX_VAR          "www"

## Edit second file

[root@www http]# grep -n 'Server: nginx' /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_header_filter_module.c
[root@www http]# sed -i 's#Server: nginx#Server: www#g' /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_header_filter_module.c
[root@www http]# grep -n 'Server: www' /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_header_filter_module.c

## Edit third file
[root@www http]# vim /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_special_response.c 
## Edit the following files
"<hr><center>" NGINX_VER "</center>" CRLF       ## About 21 lines
"<hr><center>nginx</center>" CRLF               ## About 28 lines

## Edited content
"<hr><center>" NGINX_VER " (www.shuaige.com)</center>" CRLF     ## About 21 lines
"<hr><center>www</center>" CRLF             ## About 28 lines
5. Recompile and reuse curl Command view


[root@www nginx-1.9.9]# service nginx stop
[root@www nginx-1.9.9]# cd /home/oldboy/tools/nginx-1.9.9
[root@www nginx-1.9.9]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.9.9/ --with-http_stub_status_module --with-http_ssl_module
[root@www nginx-1.9.9]# make
[root@www nginx-1.9.9]# make install
[root@www nginx-1.9.9]# service nginx start
[root@www nginx-1.9.9]# curl -I 127.0.0.1

Change the default user of the Nginx service

## View default users corresponding to Nginx service
[root@www ~]# cd /application/nginx/conf
[root@www conf]# grep '#user' nginx.conf.default
## Create new users for Nginx service
[root@www ~]# useradd nginx -s /sbin/nologin -M
[root@www ~]# id nginx  ## Checking users


## Method 1 for configuring Nginx users
[root@www ~]# vim /application/nginx/conf
## Default #Change user nobody to user nginx nginx

## Method 2 for configuring Nginx users
//Add two parameters -- user=nginx and group=nginx when compiling
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.9.9/ --with-http_stub_status_module --with-http_ssl_module

## Check the user status of Nginx
[root@www conf]# ps -ef|grep nginx|grep -v grep

Keywords: Nginx curl vim Linux

Added by bschultz on Sun, 05 Apr 2020 19:50:47 +0300