网站建设和技术服务合同,软件开发过程管理工具,聊城手机网站公司,iis如何添加网站文章目录 1、使用Nginx增加认证。2、使用Spring Gateway增加认证 SkyWalking的可视化后台是没有用户认证功能的#xff0c;默认下所有知道地址的用户都能访问#xff0c;官网是建议通过网关增加认证。 本文介绍通过Nginx和Spring Gateway两种方式 1、使用Nginx增加认证。
生… 文章目录 1、使用Nginx增加认证。2、使用Spring Gateway增加认证 SkyWalking的可视化后台是没有用户认证功能的默认下所有知道地址的用户都能访问官网是建议通过网关增加认证。 本文介绍通过Nginx和Spring Gateway两种方式 1、使用Nginx增加认证。
生成密钥
yum install -y httpd-tools
htpasswd -cb nginx/htpasswd skywalking rtgdbhyffddu#配置nginx
worker_processes 1;
error_log stderr notice;
events {worker_connections 1024;
}
http {variables_hash_max_size 1024;access_log off;#ireal_ip_header X-Real-IP;charset utf-8;server {listen 8081;#auth_basic Please enter the user name and password; #这里是验证时的提示信息#auth_basic_user_file /data/skywalking/nginx/htpasswd;index index.html;location / {root html;index index.html index.htm;#auth_basic on;auth_basic Please enter the user name and password; #这里是验证时的提示信息auth_basic_user_file /etc/nginx/htpasswd;proxy_pass http://172.17.0.9:8080;# WebSocket 穿透#proxy_set_header Origin ;#proxy_set_header Upgrade $http_upgrade;#proxy_set_header Connection upgrade;}}
}密码配置/etc/nginx/htpasswd
skywalking:$apr1$FVaUB8RE$.brXLk5N.IsNRqm3.Vy2n12、使用Spring Gateway增加认证
主要是使用Spring Gateway和Spring Security的基础认证formLogin实现 pom.xml使用的依赖包
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.penngo.web.gateway/groupIdartifactIdweb_gateway/artifactIdversion1.0.0/versionpropertiesmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-loadbalancer/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-bootstrap/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion2022.0.4/versiontypepom/typescopeimport/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion3.1.0/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationmainClasscom.penngo.web.gateway.WebGatewayMain/mainClassexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build/projectWebGatewayMain.java
package com.penngo.web.gateway;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication
public class WebGatewayMain {public static void main(String[] args) {SpringApplication.run(WebGatewayMain.class, args);}
}SecurityConfiguration.java配置
package com.penngo.web.gateway;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.server.SecurityWebFilterChain;import static org.springframework.security.config.Customizer.withDefaults;EnableWebFluxSecurity
Configuration
public class SecurityConfiguration {BeanSecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {http.authorizeExchange((authorize) - authorize.anyExchange().authenticated()).cors(cors-cors.disable()).csrf(csrf-csrf.disable()).formLogin(withDefaults());return http.build();}/*** 可以在代码中配置密码也可以在application.xml中配置密码* return*/
// Bean
// MapReactiveUserDetailsService userDetailsService() {
//
// UserDetails user User.withDefaultPasswordEncoder()
// .username(admin)
// .password(123456)
// .roles(USER)
// .build();
// return new MapReactiveUserDetailsService(user);
// }
}application.yml
server:port: 8081servlet:encoding:force: truecharset: UTF-8enabled: true
spring:application:name: gatewayappsecurity:user:name: admin2password: 123456bootstrap.yml
spring:cloud:gateway:routes:- id: skywalkinguri: http://localhost:8080/# 绑定ip白名单predicates:- RemoteAddr127.0.0.1/32,192.168.245.65/32运行效果