编辑文件时,Vagrant上的网页没有更新

问题描述 投票:0回答:1

我将Vagrant上的文件命名为index.html,并将nginx配置为像my.loc这样的web服务器vhost,index.html可以在我的Mac上使用chrome访问,这是vagrant的主机。 现在的问题是: 当我编辑index.html文件时

<html>
<head>
<title>title11</title>
</head>
<body>
</body>
</html>

然后我将title11更改为title22,网页上没有更改铬。 所以首先我认为这是缓存问题,我像这样配置nginx.conf以禁止缓存:

location ~.*\.(js|css|html|png|jpg)$
{
    #expires    -1;
    add_header Cache-Control no-cache;
    add_header Cache-Control no-store;
}

它不起作用。但是,我发现如果我在流浪者上运行cmd touch /myweb/index.html,Chrome页面上的网页会发生变化,但这不是我想要的。

编辑: 这是我的nginx.conf

user nginx;
worker_processes auto;
error_log /vagrant/nginx-error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections  1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /vagrant/nginx-access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    include /vagrant/nginx-vhosts/*.conf;
}

现在我发现如果我在流浪汉中编辑linux上的index.html,然后页面将在我的Mac OS中改变chrome。所以我认为问题是关于流浪汉。

nginx vagrant
1个回答
0
投票

我终于解决了在nginx.conf中将sendfile on更改为sendfile off的问题。

我从这篇文章中得到了答案:Clear nginx Cache in Vagrant

这是因为:

Sendfile用于“在一个文件描述符和另一个文件描述符之间复制数据”,并且在虚拟机环境中运行时显然有一些真正的麻烦,或者至少在通过Virtualbox运行时。在nginx中关闭此配置会导致静态文件通过不同的方法提供,您的更改将立即反映出来并毫无疑问

© www.soinside.com 2019 - 2024. All rights reserved.