【问题标题】:Fix nginx configuration to allow iframes修复 nginx 配置以允许 iframe
【发布时间】:2020-11-01 07:24:02
【问题描述】:

我与您联系是因为我在几天内尝试将来自数字海洋的水滴添加到我网站上的 iframe 中。
它不断告诉我它不起作用,因为我在标题中检查的 X-Frame-Options 设置为相同的原点,这是真的。
我尝试了几件事来让它发挥作用。
首先,我尝试查看是否可以更改 /etc/nginx/nginx.conf 文件中的 X-Frame-Options。所以我补充说:

add_header X-Frame-Options DENY;  

我尝试了 html 位以及服务器位或位置部分,但它从未起作用,并且在查看标头响应时,我总是具有相同的来源而不是拒绝(我知道我不应该拒绝允许 iframe,但是这个是检查我是否在正确的地方表演)。
我还尝试添加一些 CSP,如下所示:

add_header Content-Security-Policy "frame-ancestors 'self' mysite.com;

但它也没有出现在我的标题中...似乎没有任何改变我的标题。我该怎么办?我尝试重新启动我的 droplet 并使用 grep 检查是否有其他地方使用 X-Frame-Options,但事实并非如此。请帮助我,因为它让我发疯。

这是我的 Nginx 配置文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
        
        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

}

这是我的 /etc/nginx/sites-enabled/default

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;


        location / {
               
                try_files $uri $uri/ =404;
        }
        server {
        listen 80;
        listen [::]:80;

        server_name sub.domain.com;

        root /var/www/sub.domain.com;
        index index.html;

        location / {
                
                try_files $uri $uri/ =404;

        }

}

【问题讨论】:

    标签: nginx iframe digital-ocean x-frame-options


    【解决方案1】:

    没错。我发现我的服务器是直接用 traefik 而不是 nginx 运行的,所以我不得不在 traefik.toml 文件中设置配置。

    【讨论】:

      猜你喜欢
      • 2019-08-27
      • 2018-12-05
      • 2023-04-03
      • 1970-01-01
      • 2018-06-13
      • 2012-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多