Nginx 防止跨站腳本 Cross-Site Scripting (XSS)
1、修改 nginx 配置
在 nginx.conf 配置文件中,增加如下配置內容:
add_header X-XSS-Protection "1; mode=block";
X-XSS-Protection 的字段有三個可選配置值,說明如下:
0: 表示關閉瀏覽器的XSS防護機制
1:刪除檢測到的惡意代碼, 如果響應報文中沒有看到X-XSS-Protection 字段,那么瀏覽器就認為X-XSS-Protection配置為1,這是瀏覽器的默認設置
1; mode=block:如果檢測到惡意代碼,在不渲染惡意代碼
修改后效果:
2、重啟 nginx 服務
systemctl restart nginx
或者
service nginx restart