在 nginx 1.15.8 中安装 more_set_headers

Cur*_*Sam 6 ubuntu nginx source apt ubuntu-16.04

Ubuntu 16 Server -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'
Run Code Online (Sandbox Code Playgroud)

在尝试安装时,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.
Run Code Online (Sandbox Code Playgroud)

为了满足依赖,我又回到了nginx 1.10

我通过添加到/etc/apt/sources.list文件来安装 nginx

# nginx
deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx
Run Code Online (Sandbox Code Playgroud)

有人可以对我的问题有所了解吗?

Cur*_*Sam 6

这就是我在 Ubuntu 16.04 上启用 more_set_headers 所做的事情,因为该模块是一个额外的模块,而不是由 nginx 创建的,@MichaelHampton 解释如下。在他的指导下,我能够使用 more_set_headers 安装 nginx。

#==  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
Run Code Online (Sandbox Code Playgroud)

完成上述操作后,我编辑/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”是否显示。一定要检查隐藏结果跟随重定向

检查标题安全的结果

希望这有助于某人