diff --git a/README.md b/README.md index 84c4582d..449a42d8 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,11 @@ MyEMS项目由下列组件构成: ### Docker Docker-compose 安装 ``` git clone https://gitee.com/myems/myems.git + +# for generate the static direction: 'build' +cd myems/web +npm run build + cd myems docker-compose up -d ``` diff --git a/Web-Dockerfile b/Web-Dockerfile deleted file mode 100644 index 0d7319be..00000000 --- a/Web-Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM nginx - -# remove the config -RUN rm /etc/nginx/conf.d/default.conf && \ - rm /etc/nginx/nginx.conf && \ - mkdir -p /usr/share/nginx/web && \ - mkdir -p /usr/share/nginx/admin - -# copy the config and web codes -COPY ./nginx.conf /etc/nginx/ -COPY ./web/build/ /usr/share/nginx/web -COPY ./admin/ /usr/share/nginx/admin -CMD ['nginx', '-c /etc/nginx/nginx.conf', '-g "daemon off;"'] \ No newline at end of file diff --git a/admin/Dockerfile b/admin/Dockerfile index ccbeba65..8b3d2691 100644 --- a/admin/Dockerfile +++ b/admin/Dockerfile @@ -1,5 +1,11 @@ FROM nginx -WORKDIR /code -COPY . /usr/share/nginx/html +# remove the config +RUN rm /etc/nginx/conf.d/default.conf && \ + rm /etc/nginx/nginx.conf && \ + mkdir -p /usr/share/nginx/admin + +# copy the config and web codes +COPY nginx.conf /etc/nginx/ +COPY . /usr/share/nginx/admin CMD ['nginx', '-c /etc/nginx/nginx.conf', '-g "daemon off;"'] \ No newline at end of file diff --git a/admin/nginx.conf b/admin/nginx.conf new file mode 100644 index 00000000..d093b30b --- /dev/null +++ b/admin/nginx.conf @@ -0,0 +1,57 @@ +user nginx; +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; + + server { + listen 8001; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/admin; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location /api { + proxy_pass http://127.0.0.1:8000/; + proxy_connect_timeout 75; + proxy_read_timeout 600; + send_timeout 600; + } + + } + +} diff --git a/docker-compose.yml b/docker-compose.yml index c6f93f91..9fa023d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,23 +32,18 @@ services: network_mode: "host" restart: always - web-docker: - build: - context: . - dockerfile: Web-Dockerfile + admin: + build: ./admin command: nginx -c /etc/nginx/nginx.conf -g "daemon off;" healthcheck: test: [ "CMD","nginx","-t" ] network_mode: "host" restart: always -# web: -# build: ./web -# command: nginx -c /etc/nginx/nginx.conf -g "daemon off;" -# healthcheck: -# test: [ "CMD","nginx","-t" ] -# network_mode: "host" -# restart: always - # ports: - # - "10001:80" - + web: + build: ./web + command: nginx -c /etc/nginx/nginx.conf -g "daemon off;" + healthcheck: + test: [ "CMD","nginx","-t" ] + network_mode: "host" + restart: always \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile index df19e649..41d7d2c8 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,5 +1,13 @@ FROM nginx -WORKDIR /code -COPY ./build/ /usr/share/nginx/html -#CMD ['nginx', '-c /etc/nginx/nginx.conf', '-g "daemon off;"'] \ No newline at end of file +# remove the config +RUN rm /etc/nginx/conf.d/default.conf && \ + rm /etc/nginx/nginx.conf && \ + mkdir -p /usr/share/nginx/web + +# copy the config and web codes +# Attention: +# You should run 'npm run build' in the web direction to generate the build direction because this's a react projection. +COPY nginx.conf /etc/nginx/ +COPY . /usr/share/nginx/web +CMD ['nginx', '-c /etc/nginx/nginx.conf', '-g "daemon off;"'] \ No newline at end of file diff --git a/web/nginx.conf b/web/nginx.conf new file mode 100644 index 00000000..1c462061 --- /dev/null +++ b/web/nginx.conf @@ -0,0 +1,56 @@ +user nginx; +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; + server { + listen 80; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/web; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location /api { + proxy_pass http://127.0.0.1:8000/; + proxy_connect_timeout 75; + proxy_read_timeout 600; + send_timeout 600; + } + + } + +}