今天更新了一个用Nginx做反向代理的vue做前端的web应该。
发现更新完vue页面之后,重启nginx或者nginx重新加载,静态页面也没有更新过来

旧的Nginx配置

这样配置更新静态页面是有问题的

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
	    listen       80;
	    server_name  localhost;
	
	    #charset koi8-r;
	
	    #access_log  logs/host.access.log  main;
	    
	    location / {
		    root   D:/police/terminal-client; 
		    index  index.html index.htm;
		}
		
		location /api/ {
	    	proxy_pass      http://localhost:8888/;
            proxy_redirect  off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
	}
}

解决方法

  1. Nginx配置nginx.conf 设置sendfile为off(默认为on)
  2. 重启Nginx
  3. 右键点击Chrome浏览器刷新健选择“清空缓存并硬性重新加载”(对于Chrome浏览器这一步很关键,普通刷新也不会生效。其他浏览器如火狐,普通刷新就行)

改后Nginx配置

增加下面这货
http{
     sendfile off;
}

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        off;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
	    listen       80;
	    server_name  localhost;
	
	    #charset koi8-r;
	
	    #access_log  logs/host.access.log  main;
	    
	    location / {
		    root   D:/police/terminal-client; 
		    index  index.html index.htm;
		}
		
		location /api/ {
	    	proxy_pass      http://localhost:8888/;
            proxy_redirect  off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
	}
}

Nginx sendfile配置

sendfile: 设置为on表示启动高效传输文件的模式。sendfile可以让Nginx在传输文件时直接在磁盘和tcp socket之间传输数据。如果这个参数不开启,会先在用户空间(Nginx进程空间)申请一个buffer,用read函数把数据从磁盘读到cache,再从cache读取到用户空间的buffer,再用write函数把数据从用户空间的buffer写入到内核的buffer,最后到tcp socket。开启这个参数后可以让数据不用经过用户buffer。

Logo

前往低代码交流专区

更多推荐