基于Vue2和Node.js的反欺诈系统设计与实现 (13)

nginx.conf配置文件如下

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include 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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream eggServer { server hzga-be:7001; } server { listen 80; server_name hzga-fe; #charset koi8-r; #access_log logs/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ =404; } location /prod-api { rewrite /prod-api/(.*) /$1 break; client_max_body_size 100M; proxy_pass ; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } #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 html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass ; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } 后端 (以hzga-be为例)

参考楼上hzga-fe的释义。

FROM node:14.8.0 MAINTAINER ataola <zjt613@gmail.com> WORKDIR /app COPY package.json ./ RUN npm install --registry=https://registry.npm.taobao.org --production COPY app ./app COPY config ./config COPY .eslintrc .eslintignore .prettierrc .autod.conf.js .editorconfig app.js jsconfig.json ./ VOLUME /app EXPOSE 7001 CMD ["npm", "run", "docker"] MySQL数据库(以hzga-mysql为例)

参考楼上的楼上hzga-fe的释义, 与之不同的是,这里通过配置设置了建库脚本,用户名密码。

FROM mysql:8.0.16 MAINTAINER ataola<zjt613@gmail.com> ENV MYSQL_DATABASE anti-fraud ENV MYSQL_ROOT_PASSWORD ataola ENV MYSQL_ROOT_HOST '%' ENV AUTO_RUN_DIR ./docker-entrypoint-initdb.d ENV INIT_SQL anti-fraud.sql COPY ./$INIT_SQL $AUTO_RUN_DIR/ RUN chmod a+x $AUTO_RUN_DIR/$INIT_SQL VOLUME /app EXPOSE 3306 docker-compose.yml的编写

我们开发会涉及到前端、后端、数据库。docker-compose可以把多个容器放在一起管理,默认会创建一个网络,通过相关的服务名就可以访问,比如说,hzga-be的后端服务想要访问hzga-mysql的数据库,那么就可以直接在配置文件中,将ip改成hzga-mysql。同理,前端nginx这边的代理,如果要访问后端,那么可以在代理的位置直接写haga-be。

docker-compose.yml文件如下:

这里表示是基于docker-compose 3.3版本的, 然后有三个service,分别是hzga-fe(前端),hzga-be(后端),hzga-mysql(MYSQL数据库),然后指定了Dockerfile的位置,制作成镜像后的名字,暴露了相应的端口,然后容器的名字,失败后的重启策略,以及建立的网络的名字,其中后端的服务hzga-be基于数据库hzga-mysql

version: '3.3' services: hzga-fe: build: context: ./anti-fraud-system-fe dockerfile: Dockerfile image: ataola/hzga-fe:0.0.1 ports: - "80:80" networks: - net-hzga container_name: hzga-fe restart: on-failure hzga-be: build: context: ./anti-fraud-system-be dockerfile: Dockerfile image: ataola/hzga-be:0.0.1 ports: - "7001:7001" depends_on: - hzga-mysql networks: - net-hzga container_name: hzga-be restart: on-failure hzga-mysql: build: context: ./database dockerfile: Dockerfile image: ataola/hzga-mysql:0.0.1 ports: - "3306:3306" networks: - net-hzga container_name: hzga-mysql restart: on-failure networks: net-hzga: driver: bridge

下面介绍下通过docker-compose管理

部署这套服务: docker-compose up -d

暂停这套服务: docker-compose pause

下线这套服务: docker-compose down

查看相关的日志: docker-compose logs, 后面可以跟容器名字

如果是docker的命令 可以用docker help查看,如果是docker-compose的命令可以用docker-compose help查看

docker-compose的介绍: https://docs.docker.com/compose/

优势

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzfxzj.html