Nginx 缓存似乎使 chrome 失败

Nginx 缓存似乎使 chrome 失败

我正在 OVH vps 上运行 MeteorJs 应用程序,位于带有 Let's encrypt SSL 证书的 Nginx 代理后面。

以前,我使用 heroku 来托管我的应用程序。

我现在面临一个问题:在 chrome 上,我“经常”在控制台日志中收到该错误消息:Uncaught SyntaxError: Unexpected end of input

我浏览过网页,发现它与缓存有关,很多问题都说我必须删除缓存。

问题是,这样做(使用 ctrl + f5 或从 chrome 工具面板)有时会起作用,但看起来非常随机,简单的刷新最终会带回错误。

我修改了 Nginx .conf 以添加我在浏览解决方案时看到的几行:

server_tokens off; # for security-by-obscurity: stop displaying nginx version

# this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

# HTTP
server {
    listen 80 default_server; # if this is not a default server, remove "default_server"
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html; # root is irrelevant
    index index.html index.htm; # this is also irrelevant

    server_name www.talkalang.com talkalang.com; # the domain on which we want to host the application. Since we set "default_server" previously, nginx will answer all hosts anyway.

    # redirect non-SSL to SSL
    location / {
        rewrite     ^ https://$server_name$request_uri? permanent;
    }
}

# HTTPS server
server {
    listen 443 ssl; # we enable SPDY here
    server_name www.talkalang.com talkalang.com; # this domain must match Common Name (CN) in the SSL certificate

    root html; # irrelevant
    index index.html; # irrelevant

    ssl_certificate /etc/letsencrypt/live/talkalang.com/fullchain.pem; # full path to SSL certificate and CA certificate concatenated together
    ssl_certificate_key /etc/letsencrypt/live/talkalang.com/privkey.pem; # full path to SSL key

    # performance enhancement for SSL
    ssl_stapling on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 5m;

    # safety enhancement to SSL: make sure we actually use a safe cipher
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-$

    # config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
    # to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
    add_header Strict-Transport-Security "max-age=31536000;";
        # If your application is not compatible with IE <= 10, this will redirect visitors to a page advising a browser update
    # This works because IE 11 does not present itself as MSIE anymore
    if ($http_user_agent ~ "MSIE" ) {
        return 303 https://browser-update.org/update.html;
    }

    # pass all requests to Meteor
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade; # allow websockets
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
        proxy_set_header X-Forwarded-Proto https;

        # this setting allows the browser to cache the application in a way compatible with Meteor
        # on every applicaiton update the name of CSS and JS file is different, so they can be cache infinitely (here: 30 days)
        # the root path (/) MUST NOT be cached
        if ($uri != '/') {
            #expires 30d;
        }
        add_header Cache-Control no-cache;
        proxy_cache off;
        expires off;
    }
}

这是我添加的行:

add_header Cache-Control no-cache;
proxy_cache off;
expires off;

而且仍然没有解决问题。我完全没有想法,我真的不熟悉admin sys和ubuntu,特别是nginx。

问题是该应用程序每天都有数百名非技术人员使用,我不能只是要求他们发送垃圾邮件 ctrl+f5 直到它起作用为止。

有人有想法吗?任何帮助将不胜感激。

感谢您。

相关内容