日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

Spring Cloud Gateway 替换 Nginx 实战

發(fā)布時(shí)間:2024/3/26 javascript 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Cloud Gateway 替换 Nginx 实战 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一?搭建?server-dataway?微服務(wù)

二?引入?pom文件

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>sdgt_parent</artifactId><groupId>com.baiyee</groupId><version>0.0.1-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>service_gateway</artifactId><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><!-- 服務(wù)注冊(cè) --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins><!-- 編譯資源文件--><resources><resource><directory>src/main/java</directory><includes><include>**/*.yml</include><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.yml</include><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build> </project>

三?配置文件

# 服務(wù)端口 server.port=8080 # 服務(wù)名 spring.application.name=service-gateway# nacos服務(wù)地址 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848#使用服務(wù)發(fā)現(xiàn)路由 spring.cloud.gateway.discovery.locator.enabled=true#設(shè)置路由id spring.cloud.gateway.routes[0].id=service-cmn #設(shè)置路由的uri spring.cloud.gateway.routes[0].uri=lb://service-cmn #設(shè)置路由斷言,代理servicerId為auth-service的/auth/路徑 spring.cloud.gateway.routes[0].predicates= Path=/admin/cmn/**#設(shè)置路由id spring.cloud.gateway.routes[1].id=service-obj #設(shè)置路由的uri spring.cloud.gateway.routes[1].uri=lb://service-obj #設(shè)置路由斷言,代理servicerId為auth-service的/auth/路徑 spring.cloud.gateway.routes[1].predicates= Path=/admin/**

四?創(chuàng)建啟動(dòng)類(lèi)

package com.baiyee.sdgt;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication public class ServerGatewayApplication {public static void main(String[] args) {SpringApplication.run(ServerGatewayApplication.class, args);} }

五 啟動(dòng)后

?六?改造前端

'use strict' const merge = require('webpack-merge') const prodEnv = require('./prod.env')module.exports = merge(prodEnv, {NODE_ENV: '"development"',//BASE_API: '"http://localhost:8201"', // 醫(yī)院、商業(yè)公司、藥房和任務(wù)分配的接口// BASE_API: '"http://localhost:8202"', // 數(shù)據(jù)字典//BASE_API: '"http://localhost:9001"', // nginx// BASE_API: '"https://easy-mock.com/mock/5950a2419adc231f356a6636/vue-admin"',BASE_API: '"http://localhost:8080"' })

七 測(cè)試

所有頁(yè)面都可以正常顯示

?

總結(jié)

以上是生活随笔為你收集整理的Spring Cloud Gateway 替换 Nginx 实战的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。