build: 文件上传配置 nginx配置

This commit is contained in:
louis 2024-02-28 10:51:39 +08:00
parent b75515bf19
commit f008d59b45
4 changed files with 100 additions and 2 deletions

View File

@ -3,7 +3,8 @@ ENV = 'production'
# base api url # base api url
# VITE_BASE_API_URL = 'https://nest-api.buqiyuan.site' # VITE_BASE_API_URL = 'https://nest-api.buqiyuan.site'
VITE_BASE_API_URL = 'http://123.249.107.55' # VITE_BASE_API_URL = 'http://123.249.107.55'
VITE_BASE_API_URL = 'http://localhost'
# 公共基础路径, 所有资源的路径都将据此配置重写。 # 公共基础路径, 所有资源的路径都将据此配置重写。
VITE_BASE_URL = /api VITE_BASE_URL = /api

View File

@ -24,6 +24,6 @@ FROM nginx:alpine as production
ARG PROJECT_DIR ARG PROJECT_DIR
COPY --from=builder $PROJECT_DIR/dist/ /usr/share/nginx/html COPY --from=builder $PROJECT_DIR/dist/ /usr/share/nginx/html
# COPY --from=builder $PROJECT_DIR/nginx.conf /etc/nginx/nginx.conf COPY --from=builder $PROJECT_DIR/nginx.conf /etc/nginx/nginx.conf
EXPOSE 80 EXPOSE 80

View File

@ -7,8 +7,15 @@ services:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
target: production target: production
container_name: huaxin-base-frontend
ports: ports:
- '80:80' - '80:80'
env_file: env_file:
- .env - .env
- .env.production - .env.production
networks:
- nest_front_net
networks:
nest_front_net:
external:
name: nest_admin_net

90
nginx.conf Normal file
View File

@ -0,0 +1,90 @@
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;
map $time_iso8601 $logdate {
'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
default 'date-not-found';
}
log_format main '$remote_addr [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer"';
root /var/log/nginx;
access_log /var/log/nginx/access-$logdate.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
absolute_redirect off; #取消绝对路径的重定向
sendfile on;
default_type application/octet-stream;
gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 256;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;
root /usr/share/nginx/html;
location / {
# same docker config
root /usr/share/nginx/html;
index index.html;
# support history mode
try_files $uri $uri/ /index.html;
}
# 后端服务
location ^~ /api/ {
proxy_pass http://nest-admin-server:7001/api/; # 转发规则
proxy_set_header Host $proxy_host; # 修改转发请求头,让目标应用可以受到真实的请求
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# websocket服务
location ^~ /ws-api/ {
proxy_pass http://nest-admin-server:7002/ws-api/;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
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_http_version 1.1;
}
# 文件访问
location ^~ /upload/ {
proxy_pass http://nest-admin-server:7001/upload/;
proxy_set_header Host $proxy_host; # 修改转发请求头,让目标应用可以受到真实的请求
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}