Nginx 无法添加标头

时间:2021-03-16 20:38:30

标签: nginx deployment server http-headers

我有 Nginx 配置文件。这是在我改变之前

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
.......

我想在响应中添加一些标题:

server_tokens off;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

但是当我在 nginx.conf 中添加任何这些字符串时,它会引发错误:

nginx: [emerg] "add_header" directive is not allowed here in /etc/nginx/nginx.conf:1

我见过的所有示例都在 add_header 的开头使用了 server_tokensnginx.conf,但我不能。 我该怎么办?

0 个答案:

没有答案
相关问题