nginx 中http协议的相关配置

http {
... ...
server {
...
server_name
root
location [OPERATOR] /uri/ {
...
}
}
server {
...
}
}

  一、在响应报文中将指定的文件扩展名映射至MIME对应的类型

MIME=多媒体的邮件扩展

存放位置=httpserverlocation

如果这个文件中没有的后缀会用default_type

/etc/nginx/mime.types

include /etc/nginx/mime.types;
default_type application/octet-stream; 除上面指定的类型外,就为默认的MIME类型,浏览器一般会提示下载

  在配置文件中这里可以看到默认的格式是什么,不指定的话默认是文本

cat /etc/nginx/nginx.conf |grep defa
    default_type  application/octet-stream;

如果格式是在mine.types中没有的话,当从浏览器打开会提示下载,如果是文本文件的话,有些浏览器会打开,有些会提示下载。

MIME参考文档:
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_Types

    二、是否显示字符集

charset utf-8;

是否在响应报文中的Content-Type显示指定的字符集,默认off不显示

  三、设置版本号

  1、不显示版本号

server_tokens off;

  2、自定义版本号(商业版或自己编译的版本有效)

    1)、进入编译的时候的源码包

cd /data/nginx-1.21.0/src/core/

    2)、找到nginx.h的文件,编辑它

vim nginx.h

    3)、如果server_tokens on,修改这行

#define NGINX_VERSION      "1.21.0"

  #define NGINX_VER "nginx/" NGINX_VERSION

修改为:

#define NGINX_VERSION      "6.1.8"
#define NGINX_VER          "alexnginx/" NGINX_VERSION

    4)、如果server_tokens off,修改这个文件的49行

vim +49 /data/nginx-1.21.0/src/http/ngx_http_header_filter_module.c 

修改为:

static u_char ngx_http_server_string[] = "Server: apache" CRLF;

     5)、修改后,需要重新编译安装

cd /data/nginx-1.21.0
./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
make  && make install

这里就能体现nginx的好处,这里编译安装好了,之前访问的用户不会有任何影响,重启服务后,之前访问的用户才会访问新的nginx

     

------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------- 博客均为个人笔记,无所追求,仅供参考~~~ QQ--2382990774
原文地址:https://www.cnblogs.com/alexlv/p/14821742.html