weixin_38816126
2022-01-20 15:14
采纳率: 55.6%
浏览 508
已结题

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

前端为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>






  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

20条回答 默认 最新

相关推荐 更多相似问题