NGINX 不会随机加载 CSS 文件

NGINX 不会随机加载 CSS 文件

我最近从 apache2 迁移到了 nginx。

一切正常,但有时(只有 2% 的时间),加载速度会非常慢,大约 5-10 秒,然后 html 会加载,但 css 不会加载。

这不是性能问题,因为我在 preProd 中已经发现了错误,只允许我登录服务器(使用 UFW 阻止了我之外的所有 IP)。我认为这是因为当时我在上传文件时正在刷新,但现在我们上线了,人们抱怨我没有推送文件。

Nginx 直接提供 PHP/HTML/CSS/JS 文件。我还有一个用于处理 websocket 的 nodejs 服务器,但它只能做这些。

我没有调整 nginx 配置,这是我的 vhost:

server {
    listen 80;
    server_name www.mywebsite.com mywebsite.com;

    return 301 https://mywebsite.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.mywebsite.com;

    return 301 $scheme://mywebsite.com$request_uri;
}

server {

    ## SSL settings

    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    server_name mywebsite.com;

    root /var/www/mywebsite.com;

    index index.html index.php;


    location ~ /(includes|back/logs|ipn/includes|js_uncompiled|backups) {
        deny all;
        return 403;
    }


    #static file 404's aren't logged and expires header is set to maximum age
    location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
        access_log off;
        expires max;
    }
    
    access_log off;


    location ^~ /socket.io {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy false;

      proxy_pass http://localhost:3000;
      proxy_redirect off;

      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

    }

    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    }

    location / {
      try_files $uri $uri/ /index.html;
    }

    ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem; # managed by Certbot

    ssl_session_cache shared:SSL:50m;
    ssl_session_timeout 5m;
}

相关内容