Node project deployment https service

It’s hard to describe the joy. This time it’s really a cup of tea, a pack of cigarettes. A bug has changed a day
and I’ll describe my problem first. My webpage is configured with https certificate, but after node deployment is http service, the front end reported an error when calling the interface. : "Mixed Content: The page at'https://XXX' was loaded over HTTPS, but requested an in..."
Because I have encountered it before, I know that it was caused by using http to access the https interface or vice versa. The wave operation and the wrong method were misguided, and the mentality was broken. On the verge of giving up, I finally found a solution!
Okay, no nonsense, let’s show it, my server is apache service, and the front and back ends are vue+node+express:

The first part is the node part. It is said on the Internet that you need to configure the https open port. I didn’t do the test and don’t write this, but I don’t think it should be necessary (it won’t take effect if the server is not changed at the beginning), just in case it is written. Right.

//文件处理模块
let fs = require('fs')
//http 和 https服务模块
let http = require('http')
let https = require('https')
//配置你的证书,注意这里的证书是nginx的,不管你服务器用的是apache还是什么这里只要放nginx就好了
const httpsOption = {
    
    
    key: fs.readFileSync("./https/4432850_www.czjdream.com.key"),
    cert: fs.readFileSync("./https/4432850_www.czjdream.com.pem")
}
let express = require('express');
let app = express();
//在指定端口启动你的项目
http.createServer(app).listen(8082);
https.createServer(httpsOption, app).listen(8088);

Then I used the node manager, which is the PM2 manager, and the node project is dropped on the server, and then select the file directory in PM2 and click to start it.
Then configure your apache configuration related (I used the pagoda panel, here is the default that you have configured the SSL certificate):
apache/conf/extra/httpd-ssl.conf:

# 设置监听你的端口,调用接口时就是https://xxx.com:8089
Listen 8089
# 新建一个VirtualHost,写上监听的端口
<VirtualHost *:8089>     
    ServerName   blogMaster
    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
    SSLHonorCipherOrder on
    SSLCertificateFile C:/BtSoft/apache/cert/xxxxx.crt
    SSLCertificateKeyFile C:/BtSoft/apache/cert/xxxxx.key 
    SSLCertificateChainFile C:/BtSoft/apache/cert/xxxxx.crt
	
        SSLProxyEngine on

          Proxyrequests off
<Proxy *>
         Order deny,allow
         Allow from all
 </Proxy>

<Directory />
		    Options FollowSymLinks ExecCGI
		    AllowOverride All
		    Require all granted
</Directory>

<Location />
	  # 这里是你在node里配置启动的端口,我的是8082
      ProxyPass http://localhost:8082/
      ProxyPassReverse http://localhost:8082/
</Location>
</VirtualHost>     

Remember to restart the apache service after configuration.

Wow, the mentality collapsed. I worked it out for a day and it was solved by just a few lines. That’s it? That's it?

This project refers to http://blog.csdn.net/aerchi/article/details/73605496,
but most of them are their own original summary, which is recorded here

Guess you like

Origin blog.csdn.net/qq_43511063/article/details/109785146