我在将HTTPS域指向节点js应用程序时遇到问题。该应用程序在https://domain:port后可以正常工作。但是,如果没有PORT,它将无法正常工作。
---- HTTP ----
http://abcd.com/-正常工作
---- HTTPS ----
https://localhost:3000-可以正确打开,但是它说不安全,并且证书与域而不是本地主机相关。
https://abcd.com:3000-打开安全连接
https://abcd.com-错误:连接不私有。
NODE JS代码如下:
const express = require('express') const app = express() var jwt = require('jsonwebtoken'); const https = require(“ https”); var fs = require('fs');
常量端口= 3000
const选项= { 键:fs.readFileSync(“ ../ keys.pem”,“ utf8”), 证书:fs.readFileSync(“ ../ certificate.pem”,“ utf8”) };
app.use(express.static('public'))
app.get('/',(req,res)=> { res.sendFile('/ support.js') })
app.get('/ services / jwt',(req,res)=> {
const header = { “ alg”:“ ES256”, “ typ”:“ JWT”, “孩子”:“ D87Q5LCK4T” }
const有效负载= { “ iss”:“ 4373RCB7XY”, “ iat”:Date.now()/ 1000, “ exp”:(Date.now()/ 1000)+ 15778800, }
var cert = fs.readFileSync('./ AuthKey_D87Q5LCK4T.p8'); //您下载的私钥 var token = jwt.sign(payload,cert,{header:header}); res.json({token:令牌}) })
app.listen(8080,(req,res)=> { console.log(“服务器已启动...”) })
https.createServer(options,app).listen(PORT);
<VirtualHost *:80> ServerName abcd.com ServerAlias www.abcd.com Options Indexes ProxyRequests on ProxyPass / http://192.168.1.157:8080/ ProxyPassReverse / http://192.168.1.157:8080/ </VirtualHost>
<VirtualHost *:443> ServerName https://abcd.com <Location "/"> ProxyPreserveHost On ProxyPass http://192.168.1.157:3000/ ProxyPassReverse http://192.168.1.157:3000/ </Location> </VirtualHost>
有人可以帮我吗?