https的前端怎么连接到http的后端

毕设港湾 毕业设计 1

前端为vue,部署到apache上,后端为java的网页程序,怎么将https的前端连接到http的后端上,访问后端的数据呢?

这是控制台的报错信息 Failed to load resource: net::ERR SSL PROTOCOL ERROR

Uncaught (in promise) Error: Network Error createError.js:16 at t.exports (chunk-vendors.e8a2230e.js:7:67747) at XMLHttpRequest.f.onerror (chunk-vendors.e8a2230e.js:69:30491)****_

这是http.js的代码

import axios from 'axios'


export const baseUrl = "https://*********/dataset";



// create axios instance
const instance = axios.create({
    baseURL: baseUrl,
    // withCredentials: true,
    timeout: 15000
});


//request interceptors
instance.interceptors.request.use(function (config) {
    return config;
}, function (error) {
    // reject
    return Promise.reject(error);
});


//response interceptors
instance.interceptors.response.use(function (response) {
    return response.data;
}, function (error) {
    // reject
    return Promise.reject(error);
});


export default function (method, url, data = null) {
    console.log("http.js",data);
    method = method.toLowerCase();
    if (method === 'post') {
        return instance.post(url, data)
    } else if (method === 'get') {
        return instance.get(url, { params: data })
    } else if (method === 'delete') {
        return instance.delete(url, data)
    }else if(method === 'put'){
        return instance.put(url,data)
    }else{
        console.error('unknown method '+method)
        return false
    }
}

这是httpd-vhosts.conf

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#


NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
    ServerName diesel.******
    Redirect permanent "/" "https://diesel.********"
    #DocumentRoot "D:/workspaceFinalAdmin/workspaceFinal/dataset-web/dist"
</VirtualHost>

<VirtualHost *:80>
    ServerName neuron.*********
    Redirect permanent "/" "https://neuron.********"
    #DocumentRoot "D:/NEURON/Software/neuron-treeviz/neuron-treeviz/web/frontend/dist"
    #Redirect permanent "/" "https://localhost/"
</VirtualHost>

<VirtualHost *:443>
#<VirtualHost _default_:443>
    #Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    ServerName *******

    #RewriteEngine On
    #RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

    #Redirect "/" "https://*******"

    DocumentRoot "D:/NEURON/Software/neuron-treeviz/neuron-treeviz/web/frontend/dist"
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" combined
    <Directory "D:/NEURON/Software/neuron-treeviz/neuron-treeviz/web/frontend/dist">
        Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile "D:/NEURON/SSL certificates/**********.crt"
    SSLCertificateKeyFile "D:/NEURON/SSL certificates/**********。key"
    SSLCertificateChainFile "D:/NEURON/SSL certificates/DigiCertCA.crt"
    <Location "/api">
        ProxyPass "http://127.0.0.1:8000"
        ProxyPassReverse "http://127.0.0.1:8000"
    </Location>
</VirtualHost>

<VirtualHost *:443>
#<VirtualHost _default_:443>
    #Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    ServerName diesel.********

    #RewriteEngine On
    #RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

    #Redirect "/" "https://***********"

    DocumentRoot "D:/workspaceFinalAdmin/workspaceFinal/dataset-web/dist"
    #ErrorLog "logs/localhost-error_diesel.log"
    #CustomLog "logs/localhost-access_diesel.log" combined
    <Directory "D:/workspaceFinalAdmin/workspaceFinal/dataset-web/dist">
        Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile "D:/DIESEL/SSL certificates/**********.crt"
    SSLCertificateKeyFile "D:/DIESEL/SSL certificates/**********.key"
    SSLCertificateChainFile "D:/DIESEL/SSL certificates/DigiCertCA.crt"
    <Location "/api">
        ProxyPass "http://127.0.0.1:3000"
        ProxyPassReverse "http://127.0.0.1:3000"
    </Location>
</VirtualHost>

回复

共1条回复 我来回复
  • 代码驿站
    这个人很懒,什么都没有留下~
    评论

    把后端改造一下支持HTTPS, 例如使用nginx代理配置同时支持http和https,找一下运维大大,分分钟帮你搞定,需要配置SSL证书

    httpd修改参考,httpd使用较少,具体参数问友再上网查下 全站重定向多个页面:

    <VirtualHost *:80>
        ServerName w1.com
        RedirectMatch ^/(.*)$ http://w2.com/$1
    </VirtualHost>
    

    http重定向https:

    <VirtualHost *:80>
        ServerName www.w1.com
        ServerAlias w1.com
        RewriteEngine On
        RewriteCond %{HTTPS} !=on
        RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
    </VirtualHost>
    
    0条评论

发表回复

登录后才能评论