さくらインターネットVPSで、Linux + Nginx + SiteGuard 環境を構築した際、セキュリティを上げるためにNginxを使っていることを秘匿しようと、httpヘッダーからNginxの情報を削除したソースコードを makeしインストールしたら、WEBブラウザでHTMLを処理できない不具合が発生しハマった。
httpヘッダーからNginx情報を削除する作業(不具合が発生するパターン)
1 2 3 |
# vi /root/src/nginx-1.27.2/src/http/ngx_http_header_filter_module.c |
1 2 3 4 5 |
static u_char ngx_http_server_string[] = "Server: nginx" CRLF; static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF; |
上記ソースコードを下記のように編集すると、httpヘッダーからNginx情報は削除されるが、WEBブラウザには HTMLがテキストで表示される不具合が発生する。
1 2 3 4 5 |
static u_char ngx_http_server_string[] = "" CRLF; static u_char ngx_http_server_full_string[] = "" CRLF; static u_char ngx_http_server_build_string[] = "" CRLF; |

Nginxからのレスポンスが終わらず、WEBブラウザが 1.1minで Timeoutした後、WEBブラウザには HTMLがテキストで表示されるという事象。

httpヘッダーからNginx情報を削除する作業(不具合は発生しないパターン)
“Server: ” だけ残せば、httpヘッダーからNginx情報は削除されるが、不具合は発生しない。
1 2 3 |
# vi /root/src/nginx-1.27.2/src/http/ngx_http_header_filter_module.c |
1 2 3 4 5 |
static u_char ngx_http_server_string[] = "Server: " CRLF; static u_char ngx_http_server_full_string[] = "Server: " CRLF; static u_char ngx_http_server_build_string[] = "Server: " CRLF; |
HTMLはWEBページとして処理され表示される。



今回の事象に遭遇した環境はこちら
OS
Rocky Linux release 9.4 (Blue Onyx)
WEB
nginx-1.27.2.tar.gz
openssl-3.4.0.tar.gz
siteguard-server-edition-7.00-3.nginx.x86_64.tar.gz
コメント