我目前正在通過 SSH 連接處理 Next.js 專案(由于我的 api 請求存在 cookie 問題,我需要在 SSH 中作業)。
我還使用 Docker 為 React 和 Web 服務構建映像,因為我使用的是 nginx 服務器。因此,當我啟用我的服務時,應用程式加載,我可以訪問應用程式,當我進行更改時,它就可以作業了。但我必須重新加載瀏覽器選項卡才能看到更改。顯然我的網路服務不喜歡 webpack 的 hmr,我從中得到了這個日志:
web_1 | 192.168.10.1 - - [25/Mar/2022:08:45:03 0000] "GET /_next/webpack-hmr HTTP/1.1" 404 936 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36"
這是我的 docker-compose.yml:
version: '3'
services:
web:
networks:
- webgateway
- default
build: ./docker/web
depends_on:
- react
volumes:
- $PWD/docker/web/etc/nginx.conf:/etc/nginx/nginx.conf
- $PWD/docker/web/etc/default.conf:/etc/nginx/conf.d/default.conf
labels:
traefik.enable: true
traefik.http.routers.test.tls: false
react:
networks:
- default
build: ./frontend
environment:
HOST_LOCAL: $HOST_LOCAL
COMPOSE_PROJECT_NAME: $COMPOSE_PROJECT_NAME
env_file:
- .local
volumes:
- ./frontend:/opt/services/react
networks:
webgateway:
external: true
這是我的服務網站的組態檔:
碼頭工人/網路/碼頭檔案:
FROM nginx:1.13-alpine
RUN apk update && apk add bash
docker/web/etc/default.conf :
upstream app {
server react:3000;
}
server {
listen 80;
charset utf-8;
client_max_body_size 20M;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
location /api/v {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_api;
}
location @proxy_to_app {
proxy_connect_timeout 600s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
docker/web/etc/default.conf :
user root;
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;
}
提前感謝您的時間。
uj5u.com熱心網友回復:
我想通了,是next/webpack_hmr配置問題,和docker或者ngnix配置無關...
使用中間件重繪 模塊解決了我的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/453178.html
標籤:码头工人 nginx SSH 下一个.js webpack-hmr
上一篇:包含多個服務的Docker容器
