gpt4 book ai didi

docker - 如何删除 nginx docker 容器中的服务器 header ?

转载 作者:行者123 更新时间:2023-12-02 18:08:33 27 4
gpt4 key购买 nike

我通过 docker-compose 文件安装 nginx:1.15.6 容器,我想从所有 nginx 响应中删除 Server header ,通过搜索我发现如下方式
设置“more_set_headers '服务器:自定义';”在 nginx 配置中但有一个错误响应。如何删除 nginx docker 中的服务器 header ?我想我应该安装“headers-more-nginx-module-0.33”模块,但我不知道如何安装它:(

错误 :

[emerg] 1#1: unknown directive "more_set_headers" in /etc/nginx/conf.d/default.conf:22

docker 撰写文件:
version: '3'

services:
web:
build:
context: nginx
container_name: r_nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./code:/code
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/ssl:/etc/ssl
- ./nginx/logs:/var/log/nginx
restart: always
depends_on:
- php
php:
build: phpfpm
container_name: r_php
restart: always
volumes:
- ./phpfpm/raya.ini:/opt/bitnami/php/etc/conf.d/custom.ini
- ./code:/code


默认.conf:
server_tokens off;

server {
listen 80;
listen 443 ssl;
ssl on;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_certificate /etc/ssl/cert_chain.crt;
ssl_certificate_key /etc/ssl/private.key;

index index.php index.html;
#server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;

error_page 404 403 402 401 422 = /errors/error.php;
error_page 500 501 502 503 504 = /errors/error.php;

# bellow line get error :
# more_set_headers "Server: custom";

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}


location ~ /assets/ {
}

location / {
rewrite ^(.*)$ /index.php;
}
}

最佳答案

more_set_headersheaders_more 的一部分模块,所以它需要一个额外的 nginx 包才能正常工作。 nginx-extras可以在为 nginx 容器构建 docker 镜像时安装:

FROM nginx:1.15.6
RUN apt-get update && apt-get install -y nginx-extras
希望这可以帮助。

关于docker - 如何删除 nginx docker 容器中的服务器 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55722738/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com