From 99371def54f655fc0ddfd4ad7446980e199ba915 Mon Sep 17 00:00:00 2001 From: Karbob Date: Sat, 19 Nov 2022 18:35:29 +0800 Subject: [PATCH] refactor(dockerfile): separate nginx config from `Dockerfile` --- Dockerfile | 29 +---------------------------- docker/nginx.conf.example | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 docker/nginx.conf.example diff --git a/Dockerfile b/Dockerfile index a2f91f1..19d3817 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,34 +8,6 @@ COPY . . RUN yarn build FROM nginx:1.20.2-alpine as app -RUN echo $'server { \n\ - gzip on;\n\ - listen 80; \n\ - listen [::]:80; \n\ - server_name localhost; \n\ - \n\ - location / { \n\ - root /usr/share/nginx/html; \n\ - index index.html; \n\ - try_files $uri $uri/ /index.html; \n\ - } \n\ - \n\ - location @rewrites { \n\ - rewrite ^(.*)$ /index.html last; \n\ - } \n\ - \n\ - location /api/ { \n\ - proxy_buffer_size 128k; \n\ - proxy_buffers 16 32k; \n\ - proxy_busy_buffers_size 128k; \n\ - proxy_set_header Host $host; \n\ - proxy_set_header X-Real-IP $remote_addr; \n\ - proxy_set_header X-Forwarded-For $remote_addr; \n\ - proxy_set_header X-Forwarded-Host $remote_addr; \n\ - proxy_set_header X-NginX-Proxy true; \n\ - proxy_pass http://localhost:3000/; \n\ - } \n\ - }' > /etc/nginx/conf.d/default.conf COPY --from=build /app/package.json /usr/local/lib/ @@ -44,6 +16,7 @@ RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.14/m && npm i -g $(awk -F \" '{if($2=="NeteaseCloudMusicApi") print $2"@"$4}' /usr/local/lib/package.json) \ && rm -f /usr/local/lib/package.json +COPY --from=build /app/docker/nginx.conf.example /etc/nginx/conf.d/default.conf COPY --from=build /app/dist /usr/share/nginx/html CMD nginx ; exec npx NeteaseCloudMusicApi diff --git a/docker/nginx.conf.example b/docker/nginx.conf.example new file mode 100644 index 0000000..cdab218 --- /dev/null +++ b/docker/nginx.conf.example @@ -0,0 +1,28 @@ +server { + gzip on; + listen 80; + listen [::]:80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + location @rewrites { + rewrite ^(.*)$ /index.html last; + } + + location /api/ { + proxy_buffers 16 32k; + proxy_buffer_size 128k; + proxy_busy_buffers_size 128k; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Host $remote_addr; + proxy_set_header X-NginX-Proxy true; + proxy_pass http://localhost:3000/; + } +}