Сегодня я хочу рассказать о изменении того, что все называют по разному. Кто-то называет строкой приветствия, кто-то баннером или заголовком, но обычно это называется именем сервера.
Имя сервера можно изменить в двух случаях, при сборке или пересборке, но порядок действий от этого не изменится. В любом случае нам понадобится каталог с исходниками. Показываю на примере nginx-1.11.9.
Для изменения имени сервера нужно внести правки в пару файлов, один отвечает за вывод имени в заголовках, другой за имя на страницах ошибок. Файлы лежат в каталоге /nginx-1.11.9/src/http/. Перейдем в него и продолжим.
cd nginx-1.11.9/src/http
Изменим имя сервера в заголовках.
nano ngx_http_header_filter_module.c
Найдите две строки, отвечающие за имя сервера в заголовках.
static char ngx_http_server_string[] = "Server: nginx" CRLF; static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
Измените их следующим образом, вписав нужное имя.
static char ngx_http_server_string[] = "Server: notoriously_h@rd" CRLF; static char ngx_http_server_full_string[] = "Server: notoriously_h@rd" CRLF;
Изменим имя сервера на страницах ошибок.
nano ngx_http_special_response.c
Найдите следующие строки, отвечающие за имя сервера на страницах ошибок.
static u_char ngx_http_error_full_tail[] = "<hr><center>" NGINX_VER "</center>" CRLF "</body>" CRLF "</html>" CRLF ; static u_char ngx_http_error_tail[] = "<hr><center>nginx</center>" CRLF "</body>" CRLF "</html>" CRLF ;
Измените их следующим образом, вписав нужное имя.
static u_char ngx_http_error_full_tail[] = "<hr><center>" NGINX_VER "</center>" CRLF "</body>" CRLF "</html>" CRLF ; static u_char ngx_http_error_tail[] = "<hr><center>notoriously_h@rd</center>" CRLF "</body>" CRLF "</html>" CRLF ;
Чтобы задать конфигурацию, нужно просмотреть старую - nginx -V.
nginx -V nginx version: nginx/1.11.9 built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) built with OpenSSL 1.1.0f 25 May 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --user=nginx --group=nginx --without-http_autoindex_module --without-http_ssi_module --without-http_scgi_module --without-http_uwsgi_module --without-http_geo_module --without-http_split_clients_module --without-http_memcached_module --without-http_empty_gif_module --without-http_browser_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_mp4_module --with-http_auth_request_module --with-http_stub_status_module --with-http_random_index_module --with-http_gunzip_module --with-threads --with-openssl=/usr/local/src/openssl-1.1.0f
Задаем такую же конфигурацию.
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --user=nginx --group=nginx --without-http_autoindex_module --without-http_ssi_module --without-http_scgi_module --without-http_uwsgi_module --without-http_geo_module --without-http_split_clients_module --without-http_memcached_module --without-http_empty_gif_module --without-http_browser_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_mp4_module --with-http_auth_request_module --with-http_stub_status_module --with-http_random_index_module --with-http_gunzip_module --with-threads --with-openssl=/usr/local/src/openssl-1.1.0f
Компилируем и устанавливаем. Перед установкой стоит сделать резервные копии конфигов.
make && make install
Перезапустим сервер.
systemctl restart nginx
В ответах и на страницах ошибок можно увидеть новое имя.