2016-04-24 65 views
0

我有一个运行在端口8080上的Node.js应用程序,其中运行在前面的NGINX服务器并充当缓存反向代理。无法为由NGINX反向代理缓存的内容设置HTTP标头

我希望NGINX缓存everythnig,除了一个页面,我的应用程序的dashbaord:/dashboard

这里是我的配置至今:

server { 

    listen  80; 
    server_name mydomain.name; 

    # SECURITY 
    add_header X-Frame-Options SAMEORIGIN; 
    add_header X-XSS-Protection "1; mode=block"; 
    add_header X-Content-Type-Options nosniff; 
    add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' https://gravatar.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; object-src 'none'"; 

    ... 

    proxy_set_header  Host $host; 
    proxy_set_header X-Forwarded-For $remote_addr; 

    location/{ 
     add_header X-Proxy-Cache $upstream_cache_status; 
     proxy_cache   STATIC; 
     proxy_pass   http://127.0.0.1:8080; 
    } 

    location /dashboard { 
     proxy_pass   http://127.0.0.1:8080/dashboard; 
    } 
} 

缓存似乎工作正常,但安全性头(X-XSS-ProtectionContent-Security-Policy等)似乎只增加/dashboard,而不是像缓存页面//login

我的当前配置有什么问题吗?我能做些什么来解决这个问题?

回答

1

如果在正在处理的位置块中存在“add_headers”,则会忽略位置块外的任何“add_header”指令。由于“/ dashboard”没有“add_header”,所以服务器级别正在使用中。

docs

可能有几个add_header指令。当且仅当在当前级别上没有定义add_header指令时,这些指令才从前一级继承。

+0

就是这样。非常感谢你! – Bertrand