最近幾天剛開始接觸微信小程序的開發,才接觸到了https的概念(微信小程序中的請求必須爲https請求,否則請求沒法成功)。https算是對http的安全封裝,在http的基礎上加了ssl證書機制,此處不贅述,想要詳細瞭解自行百度區別。因此博主就在考慮怎麼讓整個小程序後臺(用的spring boot來做爲後臺)都能經過https訪問,終於通過兩天的研究,我發現了將ssl結合spring cloud的zuul(路由網關)能夠實現我想要的效果,話很少說,上步驟。程序員
點擊下載,將對應的ssl證書下載到本地spring
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> </dependency>
spring: application: name: zuul #註冊到eureka eureka: instance: lease-expiration-duration-in-seconds: 30 lease-renewal-interval-in-seconds: 10 prefer-ip-address: true instance-id: dragon client: fetch-registry: true register-with-eureka: true service-url: defaultZone: http://localhost:7001/eureka/ server: port: 443 # ssl證書相關配置 ssl: key-store: classpath:https/1538502410793.pfx key-store-password: 1538502410793 key-store-type: PKCS12 #zuul的相關配置 zuul: routes: # 須要配置路由的微服務 consumer: serviceId: eureka-consumer path: /con/** # 沒法使用服務名稱訪問 ignored-services: "*" # 訪問前添加前綴 prefix: /fengyuntec/
注意:https的默認端口爲443,這裏也建議設置成443小程序
@SpringBootApplication @EnableZuulProxy public class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class, args); } }
1508952532 博主qq,有什麼問題能夠問我,願程序員的世界一片祥和。微信小程序