centos中隐藏nginx和php的版本信息

Linux piniu 25浏览 0评论

一、关闭nginx的版本信息

打开nginx的配置文件,conf/nginx.conf ,在文件中添加或修改这一行代码:

server_tokens off; 

注:nginx.conf 部分代码如下:

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    server_tokens off; #关闭版本号显示

保存后,记得重启nginx

二、关闭php的版本信息

同样在nginx的配置文件中,我是在虚拟主机配置文件中,如 www.xxx.com.conf,添加这一行代码

fastcgi_hide_header X-Powered-By;   # 把x-powered-by隐藏掉

注:www.xxx.com.conf 部分代码如下:

server {
        listen       443 ssl;
        server_name  www.qeexue.com qeexue.com;
        root   /data/website/www.qeexue.com;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
            index  index.html index.htm index.php;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param HTTP_X_FORWARDED_PROTO $scheme;
            fastcgi_hide_header X-Powered-By;   # 把x-powered-by隐藏掉
            include        fastcgi_params;
        }

然后保存,重启nginx

三、查看结果

使用命令:curl -I https://www.xxx.com , url地址要换成自己的。访问结果如下:

已经没有了nginx 和 php的版本信息了

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • *昵称:
  • *邮箱: