Назад | Перейти на главную страницу

Установите more_set_headers в nginx 1.15.8

Сервер Ubuntu 16 - load_module modules/ngx_http_headers_more_filter_module.so не выходит коробка из свежей установки.

root@ /etc/nginx # nginx -V
nginx version: nginx/1.15.8
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --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 --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

Пока пытаюсь установить nginx-extras Я получаю ошибку зависимости.

root@ /etc/nginx # apt-get install nginx-extras
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nginx-extras : Depends: nginx-common (= 1.10.3-0ubuntu0.16.04.3) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Чтобы встретить зависимость, я возвращаюсь к nginx 1.10.

Я установил nginx, добавив в /etc/apt/sources.list файл

# nginx
deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx

Может ли кто-нибудь пролить свет на мою проблему?

Это то, что я сделал, чтобы включить more_set_headers в Ubuntu 16.04, поскольку модуль является дополнительным модулем и не создается nginx, как @MichaelHampton объясняет ниже. Под его руководством я смог установить nginx с помощью more_set_headers.

#==  I backed up my nginx folder to home    
tar -czvf /home/nginx.tar.gz /etc/nginx

#==  I removed then purged nginx - not sure if both are necessary
sudo apt remove nginx
sudo apt autoremove
sudo apt purge nginx

#==  I removed all nginx entries from /etc/apt/sources.list
nano /etc/apt/sources.list

#==  I did an apt-update and installed nginx
sudo apt update
sudo apt upgrade
sudo apt install nginx

#== I checked the version that was installed
nginx -v

#==  I then upgraded nginx to the latest stable
sudo apt install software-properties-common
nginx=stable 
sudo add-apt-repository ppa:nginx/$nginx
sudo apt update
sudo apt dist-upgrade

#==  I then installed nginx-extras
sudo apt install nginx-extras

Как только вышеуказанное было завершено, я отредактировал свой /etc/nginx/nginx.conf и добавил в качестве первой строки следующее:
load_module modules/ngx_http_headers_more_filter_module.so;

Затем я добавил в блок http следующее:
more_set_headers Server: Uber;

Я проверил, подходит ли моя конфигурация nginx -t

Наконец, я перезапустил сервер с помощью service nginx restart

В качестве последней проверки я подошел к https://securityheaders.com, чтобы узнать, отображается ли "Nginx". Обязательно проверьте Скрыть результаты и Следуйте перенаправлениям

Надеюсь, это кому-то поможет

Взгляните на мой учебник Вот для получения дополнительных сведений о том, как я это сделал в Amazon Linux (аналогично Centos / Red Hat). Я написал это некоторое время назад и иногда обновляю его, но, возможно, он не идеален. Я протестирую и обновлю еще раз, когда у меня будет время.

cd /home/ec2-user
mkdir nginx-build
cd nginx-build
service nginx stop
yum groupinstall "Development Tools"
yum install pcre-devel zlib-devel openssl-devel
wget http://nginx.org/download/nginx-1.15.8.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
git clone https://github.com/openresty/headers-more-nginx-module.git

tar -xzf nginx-1.15.8.tar.gz
tar -xzf v0.33.tar.gz


# Includes some machine specific optimisations
./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 --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --with-threads --with-file-aio --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=native' --add-module=../ngx_cache_purge-2.3 --add-module=../headers-more-nginx-module
make && make install
make clean  (NB: optional)
service nginx start

Ответ Куруиоса Сэма не объясняет, почему это происходит, и комментарий Майкла Хэмптона объясняет, я компилирую оба ниже для облегчения чтения.

Это происходит из-за того, что искомый модуль (http-more) не существует в репозитории nginx.com..

Этот список модулей можно найти в https://www.nginx.com/products/nginx/modules (отфильтровать автора по nginx).

Http-more можно найти в пакетах nginx-extras из nginx ppa.

https://launchpad.net/~nginx/+archive/ubuntu/stable


Сначала удалите репозиторий nginx.com из /etc/apt/sources.list, затем добавьте файл ppa.

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update

затем обновите nginx-common и nginx-extras

sudo apt-get install nginx-common
sudo apt-get install nginx-extras