我按照教程,在Vagrant VM上运行了一个nginx服务器(使用Chef作为配置器).我只有一个html页面,index.html如果我对它进行更改并运行,vagrant provision那么当我在浏览器中转到页面时会反映出这些更改.但是,我还有一个nginx正在服务的css和js文件,如果我对它们进行更改,即使我重新加载VM,更改也不会反映在页面上.尽管我可以通过SSH连接到VM并验证文件的较新版本确实在VM上.我无法弄清楚虚拟机甚至可以访问旧文件,因为我在进行更改时覆盖了它们.也许我的nginx配置文件出了问题?这是:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/vagrant/project/webroot;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
Run Code Online (Sandbox Code Playgroud)
我将所有3个文件(js,css和html)文件存储在webrootVM上.就像我说的那样,我可以通过SSH进入并验证它们应该是他们应该在的地方,所以我认为它必须是配置问题.我是否需要为css和js文件做一些特殊的事情?
1)您可以将缓存控制头添加到Nginx配置中.
location ~* ^.+\.(js|css)$ {
#old style: add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
#old style: add_header Pragma "no-cache";
expires -1;
sendfile off; #if you're using virtualbox (it is not about cache, but you will need it) https://www.vagrantup.com/docs/synced-folders/virtualbox.html
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2934 次 |
| 最近记录: |