修改或隱藏Nginx的版本號


隱藏版本號

    隱藏nginx的版本號很簡單,nginxHttpCoreModule提供了一條叫做server_tokens指令,我這要將這條指令設置為“server_tokens off”就可以了。

首先訪問一下,看一下現有的版本:

 

root@ mail ~]# curl --head http://192.168.3.139
HTTP/1.1 403 Forbidden
Server: nginx/0.8.53
Date: Thu, 09 Dec 2010 00:02:04 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

 

通過訪問我得到的是“Server: nginx/0.8.53”。

然后在配置文件中,http區段中插入“server_tokens  off;”,重新載入配置文件:

 

root@mail ~]# vi /usr/local/nginx0.8/conf/nginx.conf
 
worker_processes  1;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens  off;
    expires         5s;
    sendfile        on;
 
    keepalive_timeout  65;
 
include     "sites-enabled/mail*";
 
}
[root@mail ~]#service nginx reload

 

修改版本號

    修改版本號的方法可要比隱藏版本號的方法復雜一點,它需要在配置安裝nginx之前進行。下載完成nginx並解壓后,首先要對源碼進行修改,源碼文件都在二級目錄“nginx-0.8.53/src/”下,找到如下文件“src/core/nginx.h”,然后再對它進行修改,按照下面的代碼中指出的兩行(以用粗體標明):

 

root@mail nginx-0.8.53]# vi src/core/nginx.h
 
#define nginx_version         8053
#define NGINX_VERSION "10.0" #define NGINX_VER "jh/" NGINX_VERSION
 
#define NGINX_VAR          "NGINX"
#define NGX_OLDPID_EXT     ".oldbin"
 
 
#endif /* _NGINX_H_INCLUDED_ */

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM