Nginx 自定義添加Response Headers 修改server


之前說過如何隱藏Response Headers中 X-Powered-By

修改php.ini

expose_php = Off
service php-fpm reload

隱藏Nginx版本號 Server

修改nginx.conf, 在http{}添加

server_tokens off;

 

Nginx自定義Response Headers

 

add_header key 'value';
  server {
            listen 80 ;
            server_name ***.com;
            index index.html index.htm index.php;
            root  /home/wwwroot/***/backend/web;     
        autoindex  on;
        include enable-php.conf;  
        add_header aaa 'bbb';
        
        access_log  /home/wwwlogs/access.log;
        if (!-e $request_filename){
                rewrite ^/(.*) /index.php?r=$1 last;
            }
        }

 

nginx -t
service nginx reload

 

 

自定義修改Nginx的server

1: 修改server要在編譯Nginx修改/src/core/nginx.h文件

#define NGINX_VERSION    "1.14"  
#define NGINX_VER       "nginx" 

 

 

2: 修改src/http/ngx_http_header_filter_module.c

static char ngx_http_server_string[]="Server: nginx" CRLF;

3: 修改src/http/ngx_http_special_response.c

static u_char ngx_http_error_tail[]="<hr><center>nginx</center>" CRLF

執行下列代碼查看nginx的配置

nginx -V

然后configure 加上參數

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module
make && make install

 

 

 


免責聲明!

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



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