新鲜的Ubuntu 16.04 Nginxconfiguration服务旧的静态文件

我有一个非常基本的登陆页面。 在过去的几天里,我一直在打一个非常奇怪的问题。

例如,该目录包含:

vanilla> ./files/ ./index.html ./main_style.css files> ./back.gif ./back1.gif ./logo.png 

index.html的内容:

 <!DOCTYPE html> <html> <head> <title>Vanilla</title> <link rel="stylesheet" type="text/css" href="main_style.css"/> </head> <body> <div> <img class="logo" src="files/logo.png" /> </div> </body> </html> 

main_style.css的内容:

 html { background-image: url("files/back1.gif"); background-repeat: repeat; } img.logo { width: 471px; height: 384px; position: absolute; top: 50%; left: 50%; margin-left: -235px; margin-top: -192px; } 

我面临的问题是这样的:

立即在重新启动之后或者类似的东西,我打开网站,所有的静态文件加载正确,服务器上存在的版本。

但是,除此之外,如果我对main_style.css进行了更改,则不会反映任何更改。 即使在我的浏览器中打开main_style.css也不会反映这些更改,并且会显示该文件的旧版本。

也就在最近,我将test.png中的照片更名为logo.png,并在index.html中对其进行了相应的更改。 index.html文件反映了适当的变化,但是,它看不到照片“logo.png”,并且它返回一个404错误…显然在web根目录中,但它不被提供。 即使如此,即使服务器上没有这样的文件,我仍然可以通过URL访问旧照片“test.png”。

我曾经尝试过:

我知道这个问题在某种程度上与caching确实有关,而且我在网上search了很多解决scheme,而且在我的系统上似乎没有任何影响。

我也看到,在很多情况下,这种情况可能是由VirtualBox或称为Vagrant VM造成的。 我的机器从来没有这些东西上运行,我的服务器运行在我桌子下的物理PC上。

我以为这个问题可能是由于我运行了100多个更新引起的,因为我一会儿没有运行我的服务器,所以我竟然从服务器上备份了我的个人数据和Web数据,然后重新安装操作系统升级到最新版本,并从那里重新安装软件。

我刚刚完成了这个工作,重新configuration了所有的networking软件,但是肯定还是有问题。

在重新安装操作系统之后,我在机器上安装的唯一东西是:

  • 的OpenSSH服务器
  • 桑巴
  • nginx
  • MySQL的服务器
  • PHP-FPM
  • PHP,MySQL的

我已经读过,这可以通过将nginx.conf文件中的sendfile设置为off来解决,但是这并没有解决任何问题。

我的nginx.conf文件和php.ini文件都是默认的。

nginx.conf:

 user www-data; worker_processes auto; pid /run/nginx.pid; 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_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 

网站configuration:

 server { listen 80; root /usr/share/nginx/vanilla/; index index.html index.php index.htm; server_name www.website.com website.com; keepalive_timeout 10000; client_max_body_size 1024M; location / { try_files $uri $uri/ =404; #try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } } 

在这种情况下,确实与caching有关。 根本不在服务器端,或者我的浏览器端。

导致问题的caching是Cloudflare的一面。 我使用这项服务,因为我在我的家庭networking上,并希望隐藏我的IP地址。

奇怪的是,我从来没有用Cloudflare来解决这个问题。 自从我上次使用它之后,可能有些变化了。

我如何解决它:

我设置页面规则来完全停止caching在以下configuration:

  • * .website.com / *
  • website.com/*

然后完全擦除Cloudflare的存储caching,现在我不再有caching或旧文件服务的问题。