header {# disable FLoC trackingPermissions-Policy interest-cohort=()# enable HSTSStrict-Transport-Security max-age=31536000; includeSubDomains; preload# disable clients from sniffing the media typeX-Content-Type-Options nosniff# clickjacking protectionX-Frame-Options DENY# keep referrer data off of HTTP connectionsReferrer-Policy no-referrer-when-downgrade}encode zstd gzip
FLoC tracking
谷歌正在进行一项Chrome浏览器的 “起源试验”,以测试一项名为Federated Learning of Cohorts(又称 “FLoC”)的实验性新追踪功能。据谷歌称,该试验目前影响了选定地区的0.5%的用户,包括澳大利亚、巴西、加拿大、印度、印度尼西亚、日本、墨西哥、新西兰、菲律宾和美国。FLoC起源试验只影响谷歌浏览器89及以上版本。
谷歌表示,不希望加入 FLoC 的网站可以发送以下 HTTP 标头:Permissions-Policy interest-cohort=()
检测网址:https://amifloced.org/
HSTS
HSTS 是 HTTP 严格传输安全(HTTP Strict Transport Security) 的缩写。 这是一种网站用来声明他们只能使用安全连接(HTTPS)访问的方法。 如果一个网站声明了 HSTS 策略,浏览器必须拒绝所有的 HTTP 连接并阻止用户接受不安全的 SSL 证书。 目前大多数主流浏览器都支持 HSTS (只有一些移动浏览器无法使用它)。
因此,出现这个错误的原因是因为服务端的HTTPS证书被劫持了、而服务端又开启了HSTS策略导致的。完美的解决方案只有一种,就是避免网站被劫持。临时的解决方案可以通过修改浏览器配置来完成。
在浏览器(chrome)输入:chrome://net-internals/#hsts
拉到最下面,输入刚刚访问的网站域名,点击delete:
X-Content-Type-Options
浏览器如何判断一个文档的类型是txt,还是html?还是JPG? 还是XML ? …. 不同的文档类型应该使用不同的方式去显示。
比较标准的判断文档类型依据是:
1)通过HTTP 请求数据包header的Content-Type值
2)通过文件扩展名
但是这2个依据并不是每次都可靠的。有很多服务器没有被很好配置,于是就没有content-type这项。另外,很多动态的PHP/ASP生成的内容都是没有文件扩展名的,比如 http://123.com/a.php?abc=xyz 这种URL。
于是IE 加入了另外一个依据:
3)根据文档的数据内容来判断文档类型,不同的文档类型有不同的数据特征,通过这些特征来确定类型。
但是,有些时候Web开发者并不希望这么IE 自动判断,怎么办?可以通过使用X-Content-Type-Options:nosniff 选项来关闭IE的文档类型自动判断功能。
HTTP/1.1 200 OKContent-Length: 108Date: Thu, 26 Jun 2008 22:06:28 GMTContent-Type: text/plain;X-Content-Type-Options: nosniff
X-Frame-Options
X-Frame-Options HTTP 响应头是用来给浏览器指示允许一个页面可否在 ,
X-Frame-Options有三种可配置值
X-Frame-Options: DENY
X-Frame-Options: SAMEORIGIN
X-Frame-Options: ALLOW-FROM https://example.com/
- DENY
表示该页面不允许在 frame 中展示,即便是在相同域名的页面中嵌套也不允许
- SAMEORIGIN
表示该页面可以在相同域名页面的 frame 中展示
- ALLOW-FROM uri
表示该页面可以在指定来源的 frame 中展示
Referrer-Policy
Referrer
Referrer是HTTP请求header的报文头,用于指明当前流量的来源参考页面。通过这个信息,我们可以知道访客是怎么来到当前页面的。这对于Web Analytics非常重要,可以用于分析不同渠道流量分布、用户搜索的关键词等
但是,这个字段同时会造成用户敏感信息泄漏(如:带有敏感信息的重置密码URL,若被Web Analytics收集,则存在密码被重置的危险)
Referrer Policy States
新的Referrer规定了五种策略:
- No Referrer:任何情况下都不发送Referrer信息
- No Referrer When Downgrade:仅当协议降级(如HTTPS页面引入HTTP资源)时不发送Referrer信息。是大部分浏览器默认策略
- Origin Only:发送只包含host部分的referrer
- Origin When Cross-origin:仅在发生跨域访问时发送只包含host的Referer,同域下还是完整的。与Origin Only的区别是多判断了是否Cross-origin。协议、域名和端口都一致,浏览器才认为是同域
- Unsafe URL:全部都发送Referrer信息。最宽松最不安全的策略
SSL检查
https://www.ssllabs.com/ssltest/
https://myssl.com/
实例
server {
listen 80;
listen [::]:80;
server_name phus.lu www.phus.lu;
access_log /var/log/nginx/phus_lu.log;
error_log /var/log/nginx/phus_lu.error.log;
charset utf-8;
server_tokens off;
client_max_body_size 128M;
index index.html;
root /home/phuslu/web;
disable_symlinks off;
#add_header Strict-Transport-Security "max-age=0";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header cache-control "no-cache";
add_header access-control-allow-origin "*";
add_header referrer-policy "no-referrer";
add_header x-content-type-options nosniff;
add_header x-xss-protection "1; mode=block";
add_header x-frame-options sameorigin;
add_header x-robots-tag "noindex, nofollow";
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types text/plain text/xml text/css application/javascript application/json;
location ~ ^/(soft|tmp|z)(/|/.+/)$ {
auth_basic "Log in to continue";
auth_basic_user_file /home/phuslu/web/htpasswd.txt;
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
add_after_body /autoindex.html;
}
location ~ ^/splunk/ {
auth_basic "Log in to continue";
auth_basic_user_file /home/phuslu/web/htpasswd.txt;
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
}
location ~ ^(.*)/$ {
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
add_after_body /autoindex.html;
}
location = /ssh.keys {
default_type text/plain;
add_header x-ssh-import "curl -sS phus.lu/ssh.keys | tee -a ~/.ssh/authorized_keys";
try_files /ssh.keys =404;
}
location = /liner {
default_type text/plain;
try_files /liner/get.sh =404;
}
location = /robots.txt {
default_type text/plain;
set $robots "User-agent: *\nDisallow: /";
if ($http_user_agent ~* "^Wget") {
set $robots "";
}
return 200 $robots;
}
location = /ncsi.txt {
return 200 "Microsoft NCSI";
}
location = /generate_204 {
return 204 "";
}
location = /zoom {
return 302 "https://us04web.zoom.us/wc/join/7760708665?pwd=eEdvOWZJSXZPMnRGVXRTREtCREc0dz09";
}
location = /jsonrpc {
proxy_pass http://127.0.0.1:6800;
proxy_http_version 1.1;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
include fastcgi_params;
}
location ~ \.md$ {
default_type text/html;
add_after_body /markdown.html;
}
location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$ {
expires 1d;
access_log off;
add_header Pragma public;
}
location ~ \.(log|pac|keys|lua|json|yaml|toml|conf|cmd|sh|bash|h|c|cpp|hpp|py|go|service)$ {
default_type text/plain;
}
location ~ ^/(bashrc|vimrc)$ {
default_type text/plain;
}
}
server {
listen 80;
listen [::]:80;
server_name ip.phus.lu;
more_clear_headers 'Date';
more_clear_headers 'Server';
more_clear_headers 'X-Powered-By';
more_clear_headers 'Content-Type';
more_clear_headers 'Connection';
access_log /var/log/nginx/ip_phus_lu.log;
error_log /var/log/nginx/ip_phus_lu.error.log;
location / {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /home/phuslu/web/server/geoip2.php;
include fastcgi_params;
}
}
