nginx热加载不选择CSS自动更改



我正在使用nginx和docker服务css文件,然后代理它来表达但是当我修改CSS SRC文件时它不会选择

我的应用程序运行在http://localhost:3000/,但我需要手动去http://localhost:3000/css/main.css和刷新浏览器,然后回到http://localhost:3000/看到的变化,

和可能的修复?

码头工人组成

version: '3'
services:
dev-nginx:
build:
context: ./nginx/
container_name: dev-nginx
links:
- dev-node
ports:
- "3000:3000"
- "443:443"
volumes:
- ./client/dist:/usr/share/nginx/static
dev-webpack:
build:
context: ./client
container_name: dev-webpack
volumes:
- ./client/:/app
- /app/node_modules
ports:
- "8080:8080"
dev-node:
build:
context: ./server/
container_name: dev-node
environment:
- CHOKIDAR_USEPOLLING=true
- NODE_ENV=development
- PORT=3000
volumes:
- ./server/:/app
- /app/node_modules

nginx配置

upstream backend {
server dev-node:3000;
}
server {
listen       3000;
server_name  localhost;
root   /usr/share/nginx/static;
access_log  /var/log/nginx/host.access.log  main;
location ~* .(js|css|map|png|jpg|jpeg|gif|ico)$ {
expires 1d;
}
location ^~ /(audio|build|images|style) {
autoindex on;
}
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ~ /.ht {
deny  all;
}
}

默认

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
worker_connections  1024;
}

http {
include       /etc/nginx/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  /var/log/nginx/access.log  main;
#sendfile        on;
#tcp_nopush     on;
keepalive_timeout  65;
#gzip  on;
include /etc/nginx/conf.d/*.conf;
}

试试这个nginx配置:

upstream backend {
server dev-node:3000;
}
map $request_uri $nocache {
/css/main.css 1;
}
server {
listen       3000;
server_name  localhost;
root   /usr/share/nginx/static;
access_log  /var/log/nginx/host.access.log  main;
location ~* .(js|css|map|png|jpg|jpeg|gif|ico)$ {
expires 1d;
}
location ^~ /(audio|build|images|style) {
autoindex on;
}
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $nocache $http_upgrade;
proxy_no_cache $nocache;
}
location ~ /.ht {
deny  all;
}
}

最新更新