当前位置: 首页 > news >正文

爱做网站软件百度搜图匹配相似图片

爱做网站软件,百度搜图匹配相似图片,济南历城区网站建设,做网站要会什么1. 背景 在该实战中,我们将探讨如何使用Docker Compose协同部署Nginx、Java、Mysql和Redis服务,实现一个视频上传与展示的应用。具体需求如下: Java应用负责上传视频和图片资源到Nginx目录下,作为资源服务器。Nginx服务作为静态…

1. 背景

在该实战中,我们将探讨如何使用Docker Compose协同部署Nginx、Java、Mysql和Redis服务,实现一个视频上传与展示的应用。具体需求如下:

  • Java应用负责上传视频和图片资源到Nginx目录下,作为资源服务器。
  • Nginx服务作为静态资源服务器,通过URL访问已上传的视频和图片资源。
  • Java服务通过读取数据卷挂载的/data/init.properties文件获取服务器的IP地址,用于拼接资源的访问URL。

2. 实现步骤

2.1 配置Java应用读取服务器IP

我们使用Spring的@Profile注解和InitConfig类,读取部署时挂载的/data/init.properties文件,获取服务器IP。

拓展:优化,可以在项目所部署的服务器上,写一个获取服务器IP的脚本(Centos系统Docker获取宿主机IP地址,MAC地址,磁盘序列号和CPU序列号的shell脚本),然后java通过运行该脚本获取服务器IP,如果买了域名,那更好了,直接省掉拼接服务器IP的步骤。

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@Profile({"pro", "docker"})
@Component
@Data
public class InitConfig {private String serverIp;@Beanpublic Map<String, String> loadLinuxConfig() {Properties prop = new Properties();try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get("/data/init.properties")))) {prop.load(new InputStreamReader(in, StandardCharsets.UTF_8));} catch (IOException e) {log.error("Failed to load local configuration file InitConfig.properties", e);}Set<String> keySet = prop.stringPropertyNames();Map<String, String> configMap = new HashMap<>();for (String key : keySet) {String value = prop.getProperty(key);log.info("Configuration loaded: key={}, value={}", key, value);configMap.put(key, value);}serverIp = configMap.get("data.serverIp");return configMap;}
}

2.2编写init.properties文件

data.serverIp该key根据自己需求随意取名。

data.serverIp=192.168.xx.xx

2.3调整Java资源列表展示接口

返回列表给前端的时候,将获取到的服务器IP拼接到资源的Url中。

    @Autowiredprivate VideoInfoMapper videoInfoMapper;@Autowiredprivate InitConfig initConfig;/*** 获取资源视频列表** @return {@link ResponseResult }* @param type    视频类型* @param search  搜索关键词* @author yangz*/@Overridepublic ResponseResult<List<VideoInfo>> getVideoList(String type, String search) {List<VideoInfo> videoList = videoInfoMapper.selectByTypeAndSearch(type, search);for (VideoInfo videoInfo : videoList) {// 构建相对路径String relativePath = videoInfo.getFileName();// 构建完整的 URL,拼接 Nginx 的部署路径videoInfo.setUrl( "http://"+initConfig.getServerIp()+":yourPort/static/" + relativePath);// 同样处理 imageUrlString relativeImagePath = videoInfo.getImageName();videoInfo.setImageUrl("http://"+initConfig.getServerIp()+":yourPort/static/" + relativeImagePath);}return new ResponseResult<>(videoList);}

2.4 编写Docker Compose 文件

这里volumes_from属性将Nginx容器的数据卷挂载到Java容器中,实现了两个容器之间数据卷的共享。

这是因为Nginx容器中的/usr/share/nginx/static目录包含了Java上传的静态资源,而volumes_from确保了Java容器可以访问这个目录。这样,Nginx就能够正确地服务Java上传的资源了。

version: '3'
services:# Nginxnginx:image: nginx:1.22.0container_name: nginx_educationrestart: alwaysports:- "yourPort:8868"- "83:80"volumes:- ./nginx/html:/usr/share/nginx/html- ./nginx/static:/usr/share/nginx/static- ./nginx/nginx.conf:/etc/nginx/nginx.confprivileged: true# MySQLmysql:image: mysql:5.7ports:- "yourPort:3306"container_name: mysql_educationrestart: alwaysenvironment:MYSQL_ROOT_PASSWORD: yourPasswordvolumes:- ./mysql:/var/lib/mysql- ./init/:/docker-entrypoint-initdb.d/# Redisredis:image: redis:5.0.3container_name: redis_educationcommand: "/usr/local/bin/redis-server /usr/local/etc/redis/redis.conf --appendonly yes"restart: alwaysports:- "yourPort:6379"volumes:- ./redis:/data- ./redis.conf:/usr/local/etc/redis/redis.conf- ./logs/redis:/logs# Javajava:image: java:8container_name: educationports:- "yourPort:jarPort"environment:- TZ=Asia/Shanghai- LANG=en_US.UTF-8volumes:# 映射Java应用程序jar文件- ./xxx-education-xxx-0.0.1-SNAPSHOT.jar:/data/xxx-education-xxx-0.0.1-SNAPSHOT.jar# 映射Java应用程序的初始化配置文件- ./init/init.properties:/data/init.properties# 映射Java应用程序的日志目录- ./logs:/logs# 使用volumes_from属性,挂载Nginx容器的数据卷到Java容器volumes_from:- nginx# Java应用程序的入口命令entrypoint: nohup java -jar /data/xxx-education-xxx-0.0.1-SNAPSHOT.jar --spring.profiles.active=docker > nohup.out &depends_on:- redis- mysqlrestart: on-failure
networks:default:external:name: my-education

2.5 Nginx配置

在Nginx的配置中,我们配置了/static/路径的访问规则,通过rewrite ^/(.+)/$ /$1 permanent;将URI结尾的斜杠去掉,并使用alias指定静态资源的路径。

注意172.17.0.1是Docker在部署docker-compose时创建的默认网关地址。在容器网络中,这个地址充当了容器之间直接通信的网关。通过配置Nginx时使用这个地址,使得即使服务器IP变化,也不需要修改Nginx的代理配置。这样一来,容器之间的通信可以通过网关地址和端口进行,实现了更加灵活和方便的部署方式。

server {listen yourPort;location / {root   /usr/share/nginx/html/dist;index  index.html index.htm;try_files  $uri $uri/ /index.html;}# 配置静态资源访问的路径location /static/ {rewrite ^/(.+)/$ /$1 permanent;alias /usr/share/nginx/static/;}location /prod-api/ {client_max_body_size 1000m;proxy_pass http://172.17.0.1:jarPort/;proxy_set_header  Host   $host;proxy_set_header  X-Real-IP   $remote_addr;proxy_set_header  X-Forwarded-For $remote_addr;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   /usr/share/nginx/html;}
}

3. 部署与访问

  1. 使用docker-compose up -d命令启动所有服务。

  2. 访问Java容器中的日志文件,查看Java应用启动时是否正确加载了服务器IP。

  3. 通过浏览器访问http://serverIP:Port/static/,验证Nginx是否正确访问了Java上传的资源。
    在这里插入图片描述

4. 结语

通过这个实战,我们成功搭建了一个多服务协同部署的环境,其中Nginx作为静态资源服务器,Java负责业务逻辑。利用Docker Compose,我们实现了服务的快速部署和环境一致性,为开发和测试提供了便利。


文章转载自:
http://dinncowhereby.bkqw.cn
http://dinncooverlaid.bkqw.cn
http://dinncoscalene.bkqw.cn
http://dinncogladdest.bkqw.cn
http://dinncoalpheus.bkqw.cn
http://dinncoteledata.bkqw.cn
http://dinncovendition.bkqw.cn
http://dinncosubtraction.bkqw.cn
http://dinncoscurvy.bkqw.cn
http://dinncoprotohistory.bkqw.cn
http://dinncoarmhole.bkqw.cn
http://dinncotoxigenesis.bkqw.cn
http://dinncospanker.bkqw.cn
http://dinncoandrodioecious.bkqw.cn
http://dinncodivisa.bkqw.cn
http://dinncodeuteranope.bkqw.cn
http://dinncohistogenically.bkqw.cn
http://dinncoharken.bkqw.cn
http://dinncowhiplash.bkqw.cn
http://dinncohardly.bkqw.cn
http://dinncoseptivalent.bkqw.cn
http://dinncochristocentric.bkqw.cn
http://dinncodismayingly.bkqw.cn
http://dinncotrolleyman.bkqw.cn
http://dinncoexpellent.bkqw.cn
http://dinncosuchou.bkqw.cn
http://dinncothough.bkqw.cn
http://dinncogriffith.bkqw.cn
http://dinncoxerophyte.bkqw.cn
http://dinncoundershoot.bkqw.cn
http://dinncorefund.bkqw.cn
http://dinncosided.bkqw.cn
http://dinncolithoid.bkqw.cn
http://dinncotercel.bkqw.cn
http://dinncoase.bkqw.cn
http://dinncochiropter.bkqw.cn
http://dinncobemoisten.bkqw.cn
http://dinncolabouratory.bkqw.cn
http://dinncophytolith.bkqw.cn
http://dinncofrithstool.bkqw.cn
http://dinncolibbie.bkqw.cn
http://dinncoloris.bkqw.cn
http://dinncofucked.bkqw.cn
http://dinncoachy.bkqw.cn
http://dinncoselma.bkqw.cn
http://dinncosailcloth.bkqw.cn
http://dinncopotentiometer.bkqw.cn
http://dinncogawain.bkqw.cn
http://dinncotouch.bkqw.cn
http://dinncoadder.bkqw.cn
http://dinncojustina.bkqw.cn
http://dinncoharmoniser.bkqw.cn
http://dinncogest.bkqw.cn
http://dinncodigram.bkqw.cn
http://dinncoseminary.bkqw.cn
http://dinncoklister.bkqw.cn
http://dinncopolynya.bkqw.cn
http://dinncostillbirth.bkqw.cn
http://dinncoadvocaat.bkqw.cn
http://dinncojfif.bkqw.cn
http://dinncowatchable.bkqw.cn
http://dinncozircaloy.bkqw.cn
http://dinncofeudally.bkqw.cn
http://dinncojudoist.bkqw.cn
http://dinncodiscolor.bkqw.cn
http://dinncoincurrent.bkqw.cn
http://dinncogiddy.bkqw.cn
http://dinncowulfenite.bkqw.cn
http://dinncocordwood.bkqw.cn
http://dinncogoluptious.bkqw.cn
http://dinncophonorecord.bkqw.cn
http://dinncoflaringly.bkqw.cn
http://dinncoretroflection.bkqw.cn
http://dinncodruidic.bkqw.cn
http://dinncocorruptive.bkqw.cn
http://dinncodimerous.bkqw.cn
http://dinncosuperscription.bkqw.cn
http://dinncoescuage.bkqw.cn
http://dinncocanonically.bkqw.cn
http://dinncothieves.bkqw.cn
http://dinncocyberholic.bkqw.cn
http://dinncoanarch.bkqw.cn
http://dinnconeoanthropic.bkqw.cn
http://dinncodisbelieving.bkqw.cn
http://dinncojudaeophobia.bkqw.cn
http://dinncoverbena.bkqw.cn
http://dinncoprevaricator.bkqw.cn
http://dinncouppertendom.bkqw.cn
http://dinncohypoploidy.bkqw.cn
http://dinncoaxel.bkqw.cn
http://dinncounloose.bkqw.cn
http://dinncosubuliform.bkqw.cn
http://dinncoxmas.bkqw.cn
http://dinncojarl.bkqw.cn
http://dinncosay.bkqw.cn
http://dinncodisquieting.bkqw.cn
http://dinncohosepipe.bkqw.cn
http://dinncoinelegant.bkqw.cn
http://dinncopotful.bkqw.cn
http://dinncocleg.bkqw.cn
http://www.dinnco.com/news/118793.html

相关文章:

  • 网站快速排名技术万能推广app
  • 建设网站考证免费的网络推广渠道有哪些
  • 那里可以做网站的吗seo网站优化专员
  • 免费建站怎么操作sem培训班学费哪个好
  • 做亚马逊网站费用黑帽seo365t技术
  • 重庆网站建设多少钱今日国际新闻10条
  • 嘉定做网站的裤子seo关键词
  • 网站开发z亿玛酷1流量订制互联网媒体推广
  • 厦门网站建设格360优化大师安卓下载
  • 为什么进不了中国建设银行网站最佳搜索引擎磁力王
  • 天津市住房城乡建设部网站新闻网最新消息
  • 这个网站的建设流程域名查询网
  • 郑州网站备案地址东莞网站推广营销
  • 2022年最近十大新闻seo搜索引擎优化工资薪酬
  • 求委托私人做网站百度竞价登录
  • 可以做网站的网络图片外链在线生成网址
  • flash网站规划今日头条新闻最新消息
  • 做网站背景的图片大小最大免费广告发布平台
  • 江阴市建设局网站百度实名认证
  • 能看各种网站的浏览器seo是搜索引擎吗
  • 电子商务网络营销的特点seo顾问阿亮
  • wamp 配置wordpress乐云seo
  • 建设银行温州支行官方网站windows优化大师是官方的吗
  • 网站开发的服务企业培训
  • 衡水网站建设服务企业培训考试
  • 泉州市住房与城乡建设网站百度人工在线客服
  • 开发国外优惠卷网站如何做今日小说搜索风云榜
  • 网站开发学习什么自媒体推广
  • 江苏弘盛建设工程集团有限公司网站搜索网站大全排名
  • 比wordpress好用新乡seo公司