你好,我有一个很难解决这个问题,得到错误net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK) when trying to deploy on the production server.
简单的登录页面没有加载,但是当我使用命令curl
来获取页面时,它在终端中显示得非常好。
我使用Docker + Docker compose + NGINX + Nodejs + SvelteKit + PM2来配置服务器(“Debian GNU/Linux 11(bullseye)”)。
我已经建立了一个测试仓库来使它工作,然后将该配置用于真实的项目,它工作了,但我不知道为什么它在实际项目中不工作。This is the test repo
我已经搜索并尝试了我遇到的所有解决方案。
1.在location /
指令中添加网页的default.conf
文件
proxy_read_timeout 120s;
proxy_buffering off;
proxy_buffers 8 1024k;
proxy_buffer_size 1024k;
proxy_buffers 4 256k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 256k;
proxy_no_cache 1;
# even if cached, don't try to use it
proxy_cache_bypass 1;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_set_header Connection keep-alive;
proxy_set_header Content-Encoding identity;
fastcgi_read_timeout 300;
proxy_max_temp_file_size 2048m;
1.检查容器中/var/chache/nginx
和etc/nginx
文件夹的所有者:组(/var/lib/nginx
文件夹不存在)
docker compose -f docker-compose.yml exec nginx ls -l var/cache
docker compose -f docker-compose.yml exec nginx ls -l var/cache/nginx
(此处用户最初为nginx
docker compose -f docker-compose.yml exec nginx ls -l etc/nginx
1.将nginx.conf
文件的用户更改为user root;
,默认情况下使用user nginx;
。我使用root是因为我需要在服务器中以root用户的身份进行所有配置。
nginx.conf
文件中未注解的gzip on
1.检查了容器的内存使用情况,有些人说这是因为nginx无法该高速缓存中写入大量响应
- 登录页面响应大小:
curl -so /dev/null <login-url> -w '%{size_download}'
-〉24646字节= 0。023504257202148438 MB - 服务器
中的df -h
docker stats
1.在nginx容器中增加内存限制的大小:mem_limit:10240M”(10Gb) 我还没有尝试过为上下文
proxy_temp_path`更改nginx该高速缓存目录,因为我不确定该指向哪里。
- 默认.conf文件
# http
server {
listen 80;
listen [::]:80;
#
server_name ${SERVER_NAME};
#
root ${NGINX_ROOT};
location / {
fastcgi_read_timeout 300;
# proxy_no_cache 1;
# even if cached, don't try to use it
# proxy_cache_bypass 1;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_set_header Connection keep-alive;
proxy_set_header Content-Encoding identity;
proxy_buffers 16 4k;
proxy_buffer_size 2k;
# proxy_buffering off;
proxy_read_timeout 300s;
proxy_max_temp_file_size 2048m;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'Upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Redirects from port 80 to 3000
# (where app is listening, the one served by with pm2)
proxy_pass ${NGINX_PROXY_PASS};
}
}
- nginx.conf文件
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
}
- Dockerfile
## Pull the Node.js Docker base image from https://hub.docker.com/_/node
FROM node:18-slim AS build
ARG SERVER_NAME
## Set the Node environment to development to ensure all packages are installed
ENV NODE_ENV development
## Change our current working directory, where app its developed
WORKDIR /var/www/${SERVER_NAME}
## Copy over `package.json` and lock files to optimize the build process
COPY package*.json ./
## Install dependencies
RUN npm i pm2 -g
RUN npm i
RUN npm fund
# Copy all local files into the image.
COPY . .
## Generate prisma client
RUN npx prisma generate
## Set the Node environment to production
ENV NODE_ENV production
## build app
RUN npm run build && npm prune --omit=dev
## Expose port 3000 so it's accessible from outside of the Docker container
EXPOSE 3000
## Start app already built
CMD ["pm2-runtime", "build/index.js"]
- docker-compose。YML文件
## see https://docs.docker.com/compose/
version: '3.9'
services:
sinai:
container_name: sinai
image: sinai
restart: on-failure:3
deploy:
restart_policy:
condition: always
delay: 5s
window: 120s
build:
context: ./
dockerfile: ./Dockerfile.prod
args:
- SERVER_NAME=${SERVER_NAME}
env_file:
- .env
links:
- postgres
depends_on:
- postgres
environment:
- DATABASE_URL=${DATABASE_URL}
ports:
- 3000:3000
volumes:
# Ensure hot-module reload works, don't have to restart our container to see changes.
- ./:/var/www/${SERVER_NAME}
# To avoid copying over local Node modules to Docker
- docker_node_modules:/var/www/${SERVER_NAME}/node_modules
# share build and static files with nginx
- app_build:/var/www/${SERVER_NAME}/build
- app_static:/var/www/${SERVER_NAME}/static
## Execute and run the Postgres database container on port 5432.
# Access the database, set the environment
postgres:
container_name: postgres
image: postgres:14
hostname: postgres
restart: on-failure:3
deploy:
restart_policy:
condition: always
delay: 5s
window: 120s
env_file:
- .env
ports:
- ${PG_PORT}:5432
environment:
POSTGRES_USER: ${PG_USER}
POSTGRES_PASSWORD: ${PG_PASSWORD}
POSTGRES_DB: ${PG_DB}
PGDATA: ${PG_DATA}
volumes:
- pgdata:${PG_DATA}
- ./prisma/db/sinai.gz:/var/lib/postgresql/sinai.gz
##
nginx:
container_name: nginx
image: nginx
restart: on-failure:3
command: [ "nginx", "-g", "daemon off;" ]
mem_limit: "10240M"
deploy:
restart_policy:
condition: always
delay: 5s
window: 120s
env_file:
- .env
links:
- sinai
depends_on:
- sinai
ports:
- ${NGINX_HTTP_PORT}:80
environment: # las usa el .conf
- SERVER_NAME=${SERVER_NAME}
- NGINX_ROOT=${NGINX_ROOT}
- NGINX_PROXY_PASS=${NGINX_PROXY_PASS}
volumes:
- ./nginx/prod/default.conf.template:/etc/nginx/templates/default.conf.template
- ./nginx/prod/nginx.conf:/etc/nginx/nginx.conf
- app_build:/var/www/${SERVER_NAME}/build
- app_static:/var/www/${SERVER_NAME}/static
volumes:
pgdata:
docker_node_modules:
app_build:
app_static:
- package.json
{
...
"devDependencies": {
"@playwright/test": "^1.22.2",
"@sveltejs/adapter-node": "^1.0.0-next.86",
"@sveltejs/kit": "^1.0.0-next.405",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",
"prisma": "^4.0.0",
"svelte": "^3.44.0",
"svelte-check": "^2.7.1",
"typescript": "^4.7.4",
"vite": "^3.2.5"
},
"type": "module",
"dependencies": {
"@prisma/client": "^4.0.0",
"@types/cookie": "^0.5.1",
"cookie": "^0.5.0",
"cs-list": "^1.0.5",
"date-fns": "^2.29.2",
"print-js": "^1.6.0",
"svelte-forms-lib": "^2.0.1",
"yup": "^0.32.11"
}
}
我没有使用SvelteKit的最新版本,也没有使用SvelteKit的稳定版本1,因为我在发布之前就开始了这个项目,有很多更改要做,我没有时间解决由此产生的问题。所以,我只是更新到大变化之前的版本。
任何帮助将非常感激。多谢了!!
更新好的,我想知道问题是什么后,认为nginx不是问题,这是因为一个路由在te“manifest.json”没有使用正确的语法_´_()_/´我使用的是$lib,在使用完整路由后,它工作得很好
1条答案
按热度按时间2ul0zpep1#
好吧,我知道问题出在哪里了,我认为nginx不是问题所在,而是因为清单中的一个路由。json”没有使用正确的语法_´_()_/´我使用的是$lib,在使用完整路由后,它工作得很好