nginx隱藏版本號server


nginx隱藏版本號server_tokens


安全優化-隱藏版本號server_tokens

Syntax: server_tokens on | off | build | string;

Default: server_tokens on;

Context: http, server, location

在主配置文件nginx.conf、虛擬主機的配置文件中配置,選一個配置即可

官方文檔地址:http://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens

在主配置文件nginx.conf加入


<code>[root@web01 conf]# cat /application/nginx/conf/nginx.conf
worker_processes  2;
error_log logs/error.log;
 
#配置Nginx worker進程最大打開文件數
worker_rlimit_nofile 65535;
 
user www www;
events {
    #單個進程允許的客戶端最大連接數
    worker_connections  20480;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    #訪問日誌配置
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
 
    #虛擬主機
    include /application/nginx/conf/extra/www.conf;
    include /application/nginx/conf/extra/blog.conf;
    include /application/nginx/conf/extra/bbs.conf;
    include /application/nginx/conf/extra/edu.conf;
    include /application/nginx/conf/extra/phpmyadmin.conf;
    include /application/nginx/conf/extra/status.conf;
 
    #隱藏版本號
    server_tokens off;
}/<code>


在虛擬主機的配置文件中添加


<code>[root@web01 conf]# cat /application/nginx/conf/extra/www.conf 
server {
    listen  80;
    server_name www.abc.com;
    rewrite ^(.*)$  https://$host$1 permanent;
}
server {
    listen       443;
    server_name  www.abc.com;
 
    #https證書
    ssl on;
    ssl_certificate /application/nginx/conf/key/server.crt;
    ssl_certificate_key /application/nginx/conf/key/server.key;
 
    #訪問日誌
    access_log  logs/access_www.log  main buffer=32k flush=5s;
    location / {
        root   html/www;
        index  index.php index.html index.htm;
    }
    #隱藏版本號
    server_tokens off;
    #php解析
    location ~ .*\\.(php|php5)?$ {
        root html/www;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}/<code>

轉載於:https://blog.51cto.com/13673885/2299757


分享到:


相關文章: