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

apache发布多个网站网站开发和程序开发的却别

apache发布多个网站,网站开发和程序开发的却别,wordpress女性代码下载,一个网站要注意哪些问题文章目录 1.配置SSL证书使用HTTPS访问2.MINIO SDK 忽略证书验证3.使用受信任的证书 1.配置SSL证书使用HTTPS访问 生成域名对应的SSL证书,下载Apache版本,我目前只发现Apache这个里面有对应的私钥和证书 私钥重命名为private.key证书重命名为public.crt&…

文章目录

    • 1.配置SSL证书使用HTTPS访问
    • 2.MINIO SDK 忽略证书验证
    • 3.使用受信任的证书

1.配置SSL证书使用HTTPS访问

生成域名对应的SSL证书,下载Apache版本,我目前只发现Apache这个里面有对应的私钥和证书
在这里插入图片描述私钥重命名为private.key证书重命名为public.crt,不更改为指定格式则会无法被识别。
将公钥和证书放入root/.minio/certs文件夹中,此文件夹安装minio时自动生成的
在这里插入图片描述

重新启动minion可以看到启动日志中http变成了https,此时可以使用https://域名.com:9001进行访问了

2.MINIO SDK 忽略证书验证

在使用Java SDK与自签名证书的服务器进行通信时,一般可以通过自定义SSLContext来忽略证书验证。

MinIO的Java SDK(version 8.0.6及以上)允许自定义OkHttpClient,我们可以使用httpClient方法传递一个自定义的OkHttpClient实例。以便在HTTP、正常HTTPS和自签名HTTPS之间实现兼容性

下面是如何使用自定义的OkHttpClient实现对HTTP、正常HTTPS和自签名HTTPS的兼容性

@Configuration
@EnableConfigurationProperties(MinioProperties.class)
public class MinioConfig {private static final Logger LOGGER = LoggerFactory.getLogger(MinioConfig.class);@Beanpublic MinioClient minioClient(MinioProperties properties){properties.check();// Create a trust manager that does not validate certificate chainsTrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {public X509Certificate[] getAcceptedIssuers() {return new X509Certificate[0];}public void checkClientTrusted(X509Certificate[] certs, String authType) {// Do nothing (trust any client certificate)}public void checkServerTrusted(X509Certificate[] certs, String authType) {// Do nothing (trust any server certificate)}}};// Install the all-trusting trust managerSSLContext sslContext = null;try {sslContext = SSLContext.getInstance("SSL");sslContext.init(null, trustAllCerts, new java.security.SecureRandom());} catch (Exception e) {LOGGER.error("Install the all-trusting trust manager error:{}", e.getMessage());}// Create a custom OkHttpClient that trusts all certificatesOkHttpClient customHttpClient = new OkHttpClient.Builder().sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0]).hostnameVerifier((hostname, session) -> true).build();// Set the custom SSLContext for MinioClientreturn MinioClient.builder().endpoint(properties.getEndpoint()).credentials(properties.getAccessKey(), properties.getSecretKey()).httpClient(customHttpClient).build();}}

1.在上面的代码中,我们创建了一个SSLContext,其中的X509TrustManager会信任所有证书,无论其是否由信任的证书颁发机构(CA)签署。
2.创建了一个自定义的OkHttpClient,该客户端信任所有证书。然后,我们使用MinioClient.builder()方法,将自定义的OkHttpClient传递给httpClient()方法

这种方法会将所有证书都视为受信任的,因此请仅在非生产环境中使用此方法,以确保通信的安全性和完整性。在生产环境中,建议使用受信任的SSL证书。

代码优化

@Configuration
@EnableConfigurationProperties(MinioProperties.class)
public class MinioConfig {private static final Logger LOGGER = LoggerFactory.getLogger(MinioConfig.class);@Beanpublic MinioClient minioClient(MinioProperties properties){properties.check();OkHttpClient customHttpClient = null;if (properties.getEndpoint().startsWith("https://")) {// 如果是HTTPS,使用自定义的OkHttpClient处理自签名的HTTPS请求customHttpClient = createCustomOkHttpClient();}MinioClient minioClient;if (customHttpClient != null) {// 如果使用了自定义的OkHttpClientminioClient = MinioClient.builder().endpoint(properties.getEndpoint()).credentials(properties.getAccessKey(), properties.getSecretKey()).httpClient(customHttpClient).build();} else {// 如果是普通HTTP,使用默认的OkHttpClientminioClient = MinioClient.builder().endpoint(properties.getEndpoint()).credentials(properties.getAccessKey(), properties.getSecretKey()).build();}return minioClient;}/*** Set the custom SSLContext for MinioClient* @return*/private static OkHttpClient createCustomOkHttpClient() {// 创建自定义的OkHttpClient,用于处理自签名的HTTPS请求// Create a trust manager that does not validate certificate chainsTrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {public X509Certificate[] getAcceptedIssuers() {return new X509Certificate[0];}public void checkClientTrusted(X509Certificate[] certs, String authType) {// Do nothing (trust any client certificate)}public void checkServerTrusted(X509Certificate[] certs, String authType) {// Do nothing (trust any server certificate)}}};// Install the all-trusting trust managerSSLContext sslContext = null;try {sslContext = SSLContext.getInstance("SSL");sslContext.init(null, trustAllCerts, new java.security.SecureRandom());} catch (Exception e) {LOGGER.error("Install the all-trusting trust manager error:{}", e.getMessage());}// Create a custom OkHttpClient that trusts all certificatesOkHttpClient customHttpClient = new OkHttpClient.Builder().sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0]).hostnameVerifier((hostname, session) -> true)// 增加minio http请求日志打印//.addInterceptor(new CustomLoggingInterceptor()) // Add custom interceptor here.build();return customHttpClient;}}

3.使用受信任的证书

minio 8.4.4 使用自签名的https的api连接会报错证书错误

报错日志

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

问题原因
通常是因为MinIO默认情况下会验证服务器的TLS证书。在生产环境中,使用自签名证书并不推荐,因为它们不受信任的证书颁发机构(CA)签署,可能会导致安全问题。

解决问题
1.使用受信任的证书
为了在生产环境中确保安全性,建议获取一个受信任的SSL证书,可以从证书颁发机构(CA)购买,或者使用免费的证书颁发机构(例如Let’s Encrypt)获取SSL证书。
CA比较新或自行颁发的证书,需要将证书加入到jdk的信任证书库中,
把该证书导入java中的cacerts证书库里
Jdk的安装目录 C:\Program Files\Java\jdk1.8.0\jre\lib\security
执行系统命令:
1、进入安装目录
cd C:\Program Files\Java\jdk1.8.0\jre\lib\security
2、自签证书添加到jdk的信任证书库中

keytool -import -alias <alias-name> -file <certificate-file> -keystore <keystore-file> -storepass <password>

在这个命令中:

是您为导入的证书指定的别名。
是包含要导入证书的文件的路径。
是密钥库文件的路径。在Java的默认安装中,这通常是$JAVA_HOME/lib/security/cacerts,但也可以是您指定的任何其他密钥库文件。
是密钥库的密码。对于Java的默认cacerts文件,这通常是changeit,但如果您更改了密码,则需要使用新密码。

keytool -import -alias minio -file .\www.oa.cn_public.crt -keystore /home/jdk/jdk-8u251-linux-x64/jdk1.8.0_251/jre/lib/security/cacerts -storepass changeit

2.同2忽略证书验证

http://www.yayakq.cn/news/146265/

相关文章:

  • 每天网站外链做几条最好免费域名解析网站建设
  • 网站开发公共文件进入网站空间
  • 网站建设项目可行性学校门户网站功能
  • 网站建设没有业务怎么办邹城有做网站的吗
  • 网站建设公司收费聊城的网站制作公司
  • 廊坊市网站推广宝塔面板windows建站教程
  • 餐饮网站建设案例个人网站做公司网站
  • 专业的网站设计公司从事软件开发
  • 开源的网站开发软件线上宣传渠道和宣传方式
  • 做网站找我图片大气的广告公司名称
  • 购物网站欢迎页面怎么设计研发项目管理系统
  • 制作一个赚钱的网站网站建设用什么程序
  • 中装建设官方网站如何自主建设企业网站
  • 企业邮箱注册申请163免费苏州旺道seo
  • 集团网站策划方案品牌建设途径
  • 学ps做兼职的网站有哪些网页制作教程赵丰年第三版
  • 天津团购鲜花的网站建设东川网站制作
  • 网站建设及seo网页设计的原则
  • 平面设计的网站有哪些网站wordpress修改首页网址导航
  • 网站建设备案不通过中国建设银行个人登录查询入口
  • 张家港外贸型网站制作鞍山百姓网招聘信息
  • 网站建设名老薛主机多个域名WordPress
  • 一套网站开发需要多少钱网站颜色搭配网站
  • 国外做免费网站的c 做网站需要什么知识
  • 网站哪个语言好网站备案要多少天
  • 全能网站服务器discuz 转 wordpress
  • 有什么网站可以做电子版邀请函网站开发哈尔滨网站开发公司电话
  • 常州建设工程信息网站西安网站建设有那些公司
  • 网站建设cz35我想出租做房 请问哪个网站好些
  • 搭建英文网站私人可以买服务器吗