在 nGinx 静态文件构建包中添加 X-Frame-Options

Add X-Frame-Options in the nGinx Staticfile buildpack

我需要在 nginx CF 中添加以下 X-Frame 选项。

add_header X-Frame-Options "SAMEORIGIN";

我正在使用 Cloud Foundry 静态文件构建包。

如果我直接编辑 nginx.conf,它会在我部署我的应用程序时被删除。所以建议通过Staticfile buildpack添加。

但我不知道 x 帧选项的确切值。

参考:https://docs.cloudfoundry.org/buildpacks/staticfile/index.html

正确,您不想直接编辑配置文件。下次您的应用重新启动、重新暂存、重新创建、崩溃,甚至下次平台因维护而移动应用时,您的更改将消失。

如果您遵循 instructions for adding custom Nginx configuration,您可以将配置放入一个片段中,由 Staticfile buildpack 生成的 Nginx 配置将自动读取您的配置片段。

希望对您有所帮助!

Nginx.conf 文件启用 X 框架选项

location ~* \.(?:html)$ {
  try_files $uri =404;
  add_header Cache-Control  'no-cache, no-store, must-revalidate, max-age=0';
  add_header X-Frame-Options 'SAMEORIGIN';
  add_header X-Frame-Options 'DENY';
  add_header Content-Security-Policy "frame-ancestors 'self';";      
  expires 0;
}