今天更新了一個用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;
}
}
}
解決方法
- Nginx配置nginx.conf 設置sendfile爲off(默認爲on)
- 重啓Nginx
- 右鍵點擊Chrome瀏覽器刷新健選擇“清空緩存並硬性重新加載”(對於Chrome瀏覽器這一步很關鍵,普通刷新也不會生效。其他瀏覽器如火狐,普通刷新就行)
改後Nginx配置
增加下面這貨
http{
sendfile on;
}
#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。