国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Nginx配置springboot+vue項目http跳轉(zhuǎn)https

這篇具有很好參考價值的文章主要介紹了Nginx配置springboot+vue項目http跳轉(zhuǎn)https。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

java生成證書

添加依賴

<dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk15on</artifactId>
            <version>1.69</version>
        </dependency>
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.BasicConstraints;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;

import javax.security.auth.x500.X500Principal;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.*;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: moses
 * @Date: 2023/7/4
 */
public class HttpsUtil {
    //CN=名字與姓氏, OU=組織單位名稱, O=組織名稱, L=城市或區(qū)域名稱, ST=省/市/自治區(qū)名稱, C=雙字母國家/地區(qū)代碼
    public static final String NAME = "CN=moses, OU=glory2020.cn, O=glory2020, L=beijing, ST=beijing, C=CN";
    public static final String ALIAS = "king";
    public static final String PASSWORD = "!QAZ2wsx";

    public static void main(String[] args) throws Exception {
        GenerateNginxHttpsCertificate("ruoyi", "/Users/fanshaorong/Desktop/Program/ssl", "cert");
    }

    // yesterday
    public static Date getStartDate() {
        Calendar startC = Calendar.getInstance();
        startC.add(Calendar.DAY_OF_YEAR, -1);
        Date startDate = startC.getTime();
        return startDate;
    }

    // one year from now
    public static Date getEndDate() {
        Calendar endC = Calendar.getInstance();
        endC.add(Calendar.YEAR, 10);
        Date endDate = endC.getTime();
        return endDate;
    }

    public static void GenerateNginxHttpsCertificate(String hostname, String filePath, String filename) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException, CertificateException, OperatorCreationException {
        // Generate key pair
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
        generator.initialize(4096);
        KeyPair keyPair = generator.generateKeyPair();
        // Create certificate
        X500Principal issuer = new X500Principal(NAME);
        X500Principal subject = new X500Principal(NAME);
        X500Name issuerName = new X500Name(issuer.getName());
        X500Name subjectName = new X500Name(subject.getName());
        // yesterday
        Date startDate = getStartDate();
        // one year from now
        Date endDate = getEndDate();
        X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(issuerName, new BigInteger(64, new SecureRandom()), startDate, endDate, subjectName, keyPair.getPublic());
        ASN1Encodable[] subjectAlternativeNames = new ASN1Encodable[]{new GeneralName(GeneralName.dNSName, hostname),
                //  new GeneralName(GeneralName.dNSName, "www.example.com"),
                // new GeneralName(GeneralName.iPAddress, "192.168.0.1")
        };
        byte[] sanExtensionValue = new DERSequence(subjectAlternativeNames).getEncoded(ASN1Encoding.DER);
        // String dns1 = "DNS:" + hostname;
        Extension dns = new Extension(Extension.subjectAlternativeName, false, sanExtensionValue);
        builder.addExtension(dns);
        // 添加基本約束擴展
        BasicConstraints basicConstraints = new BasicConstraints(true);
        builder.addExtension(Extension.basicConstraints, true, basicConstraints.getEncoded());
        builder.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.keyCertSign | KeyUsage.cRLSign));
        // 添加Subject Key Identifier擴展
        builder.addExtension(Extension.subjectKeyIdentifier, false, new JcaX509ExtensionUtils().createSubjectKeyIdentifier(keyPair.getPublic()));
        // SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
        // 添加Authority Key Identifier擴展
        builder.addExtension(Extension.authorityKeyIdentifier, false, new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(keyPair.getPublic()));
        ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(keyPair.getPrivate());
        X509Certificate certificate = new JcaX509CertificateConverter().getCertificate(builder.build(signer));
        saveCertToFile(filePath, filename, certificate, keyPair);
    }

    public static void saveCertToFile(String filePath, String filename, X509Certificate certificate, KeyPair keyPair) throws IOException, CertificateEncodingException, NoSuchAlgorithmException, InvalidKeySpecException {
        // Write key pair and certificate to files
        FileOutputStream keyOut = new FileOutputStream(filePath + File.separator + filename + ".private.key");
        keyOut.write(keyPair.getPrivate().getEncoded());
        keyOut.close();
        FileOutputStream certOut = new FileOutputStream(filePath + File.separator + filename + ".crt");
        certOut.write(certificate.getEncoded());
        certOut.close();
        FileOutputStream out = new FileOutputStream(filePath + File.separator + filename + ".pem");
        JcaPEMWriter writer = new JcaPEMWriter(new java.io.OutputStreamWriter(out));
        writer.writeObject(certificate);
        writer.close();
        out.close();
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey key = keyFactory.generatePrivate(keySpec);
        FileOutputStream keyout = new FileOutputStream(filePath + File.separator + filename + ".key");
        JcaPEMWriter keywriter = new JcaPEMWriter(new java.io.OutputStreamWriter(keyout));
        keywriter.writeObject(key);
        keywriter.close();
        keyout.close();
        try {
            //創(chuàng)建一個空的keystore
            KeyStore keyStore = null;
            keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(null, null);
            //將密鑰對保存到keystore中
            char[] password = PASSWORD.toCharArray();
            X509Certificate[] chain = {certificate};
            keyStore.setKeyEntry(ALIAS, keyPair.getPrivate(), password, chain);
            //將keystore保存到文件
            try (FileOutputStream fos = new FileOutputStream(filePath + File.separator + filename + ".keystore")) {
                keyStore.store(fos, password);
            }
        } catch (KeyStoreException | CertificateException e) {
            e.printStackTrace();
        }
    }
}

復(fù)制keystore到springboot資源目錄,修改application.yml配置

  ssl:
    key-store: classpath:cert.keystore
    key-store-password: '!QAZ2wsx'
    key-store-type: JKS
    enabled: true

Nginx配置springboot+vue項目http跳轉(zhuǎn)https,http,nginx,spring boot

?啟動項目

Nginx配置springboot+vue項目http跳轉(zhuǎn)https,http,nginx,spring boot

nginx配置

開啟ssl

server {
        listen       443 ssl;
        server_name  localhost;
    
        ssl_certificate      /Users/fanshaorong/Desktop/Program/ssl/cert.pem;
        ssl_certificate_key  /Users/fanshaorong/Desktop/Program/ssl/cert.key;
    
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
    
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
    
        #location / {
        #    root   html;
        #    index  index.html index.htm;
        #}
		location / {
			root   /Users/fanshaorong/Desktop/Project/RuoYi-Vue3/ruoyi-ui;
			try_files $uri $uri/ /index.html;
			index  index.html index.htm;
		}
		location ~ /test-api {
			proxy_ssl_certificate     /Users/fanshaorong/Desktop/Program/ssl/cert.pem;
            proxy_ssl_certificate_key /Users/fanshaorong/Desktop/Program/ssl/cert.key;
            proxy_ssl_protocols       TLSv1 TLSV1.1 TLSv1.2;
            proxy_ssl_ciphers         ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
            proxy_ssl_session_reuse  on;
            proxy_redirect off;

			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass https://localhost:9091;
		}
    }

Nginx配置springboot+vue項目http跳轉(zhuǎn)https,http,nginx,spring boot?

server {
    listen       81;
    server_name localhost;
    return 301 https://$host$request_uri;
	#rewrite ^(.*)$  https://$host$1 permanent;	
}

Nginx配置springboot+vue項目http跳轉(zhuǎn)https,http,nginx,spring boot?

重啟nginx -s reload

訪問localhost:81將跳轉(zhuǎn)到https://localhost/login?redirect=/index

Nginx配置springboot+vue項目http跳轉(zhuǎn)https,http,nginx,spring boot

?文章來源地址http://www.zghlxwxcb.cn/news/detail-522652.html

到了這里,關(guān)于Nginx配置springboot+vue項目http跳轉(zhuǎn)https的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • nginx配置若依框架vue打包項目(同時支持http和https)

    該配置模版主要是若依框架前后端配置,若只是配置普通的vue項目,直接復(fù)制一下小模塊即可 ? #vue頁面訪問配置 ? ? ?location ?/ { ? ? ? ? ? ? ?root /www/wwwroot/www.xxx.com; ? ? ? ? ? ? # autoindex on; ? ? ? ? ? ? ?try_files $uri $uri/ /index.html; ? ? ? ? ? ? ?index ?index.html index.htm

    2024年01月25日
    瀏覽(20)
  • nginx http 跳轉(zhuǎn)到https

    改 Nginx 配置文件 在您安裝了 SSL 證書之后,您需要修改 Nginx 的配置文件以啟用 HTTPS 和 HTTP 自動跳轉(zhuǎn) HTTPS。 打開 Nginx 配置文件(通常位于 /etc/nginx/nginx.conf ),找到您的網(wǎng)站配置塊。在該配置塊中添加以下內(nèi)容: 該配置塊包括兩個部分: 第一個部分監(jiān)聽 HTTP(端口 80),并

    2024年02月06日
    瀏覽(20)
  • Nginx如何實現(xiàn)http自動跳轉(zhuǎn)到https

    本文主要介紹了Nginx實現(xiàn)http自動跳轉(zhuǎn)到https,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著微點閱讀小編來一起學(xué)習(xí)學(xué)習(xí)吧 https是更安全的http,通過http自動跳轉(zhuǎn)https,可以更便于用戶使用web。 有幾下幾個方法可以

    2024年02月11日
    瀏覽(19)
  • SpringBoot項目(Tomcat啟動https端口)——springboot配置Tomcat兩個端口,https和http的方式 & jar的打包和運行

    SpringBoot項目(Tomcat啟動https端口)——springboot配置Tomcat兩個端口,https和http的方式 & jar的打包和運行

    1.springboot配置Tomcat兩個端口,https和http的方式; 2.在https協(xié)議下,發(fā)送axios請求沒反應(yīng),暫時用form表單解決; 3.運行jar包template might not exist報錯及解決; 代碼位置: https://gitcode.net/Pireley/springboot-tomcat-http-https 嚴格來說https不是一個獨立協(xié)議,只是在http協(xié)議基礎(chǔ)上增加了SSL/T

    2024年02月03日
    瀏覽(30)
  • http自動跳轉(zhuǎn)https的配置方法

    要將HTTP自動重定向到HTTPS,您需要在Web服務(wù)器上進行以下配置: 在Web服務(wù)器上安裝SSL證書。 打開Web服務(wù)器配置文件(如Apache的httpd.conf或Nginx的nginx.conf)。 找到監(jiān)聽HTTP請求的端口(通常是80端口)。 添加以下代碼將HTTP請求重定向到HTTPS: 對于Apache服務(wù)器: 對于Nginx服務(wù)器:

    2024年02月03日
    瀏覽(20)
  • Nginx配置HTTPS跳轉(zhuǎn)到非443端口的技巧和注意事項

    近一段時間由于看到v*云服務(wù)廠商有活動,就注冊并開了臺云服務(wù)器,試一下區(qū)別。 (“充10美元送30天內(nèi)有效的250美元的免費額度,意思是30天內(nèi)在 你加起來 不超出250美元的 服務(wù)隨便開,但是注意的是30天后這就不免費了,記得及時關(guān)閉。只支持paypal,而阿里alipay一般是充值

    2023年04月18日
    瀏覽(20)
  • Nginx配置http和https

    配置文件 默認放置位置:{nginx}/conf.d/,以conf結(jié)尾 一、http簡單配置 說明: 1,http默認端口是80 2,http://127.0.0.1:8888;為實際本地服務(wù)端口 3,一般服務(wù)域名為二級域名www,一級域名一般也配置指向www域名。 二、https配置 首先得申請ssl證書,百度,阿里都有免費證書可用,申請成

    2023年04月09日
    瀏覽(56)
  • Centos7通過nginx+tomcat部署Vue+SpringBoot項目(超詳細步驟,從nginx+tomcat安裝到Vue+SpringBoot打包配置+nginx.conf)

    Centos7通過nginx+tomcat部署Vue+SpringBoot項目(超詳細步驟,從nginx+tomcat安裝到Vue+SpringBoot打包配置+nginx.conf)

    目錄 一丶前言 二、安裝nginx 1.準備nginx 2.服務(wù)器上傳nginx 3.解壓nginx? 4.安裝相關(guān)依賴庫 5.編譯nginx 6.啟動nginx 7.訪問nginx? 8.安裝成系統(tǒng)服務(wù) 三、安裝Tomcat 1.安裝JDK(如果安裝并配置環(huán)境變量了可以略過) 2.準備Tomcat 3.服務(wù)器上傳tomcat 4.解壓tomcat? 5.啟動tomcat 6.訪問tomcat 7.設(shè)置

    2024年02月05日
    瀏覽(26)
  • 【nginx】配置將HTTPS請求轉(zhuǎn)換成HTTP

    要將HTTPS請求轉(zhuǎn)換為HTTP請求,可以在Nginx的配置文件中添加以下配置: 打開Nginx的配置文件,通常位于 /etc/nginx/nginx.conf 或 /etc/nginx/conf.d/default.conf 。 在 server 塊中添加以下配置,將HTTPS請求轉(zhuǎn)發(fā)到后端的HTTP服務(wù): 將 yourdomain.com 替換為你的域名, /path/to/your/ssl_certificate.crt 和

    2024年02月10日
    瀏覽(23)
  • nginx配置http請求轉(zhuǎn)成https請求

    1、return 301 2、rewitre 3、error_page 原理: http和https是tcp的上層協(xié)議,當(dāng)nginx服務(wù)器建立tcp連接后,根據(jù)收到的第一份數(shù)據(jù)來確定客戶端是希望建立tls還是http。nginx會判斷tcp請求的首寫節(jié)內(nèi)容以進行區(qū)分,如果是0x80或者0x16就可能是ssl或者tls,然后嘗試https握手。如果端口開啟了

    2024年02月07日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包