首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Node.js应用程序通过超文本传输协议工作,但不能通过超文本传输协议工作

问Node.js应用程序通过超文本传输协议工作,但不能通过超文本传输协议工作
EN

Stack Overflow用户
提问于 2020-07-19 14:07:39
回答 1查看 30关注 0票数 0

我正在尝试通过Node.js协议在我的服务器上运行一个HTTPS + Vue.js + Apache + MySQL应用程序。(在本地或通过HTTP在服务器上运行良好)。

有一个API的URL (子域),它返回一个JSON结果,假设是"api.mysite.com“。

我尝试了不同的方法,现在我在我的app.js中使用端口443 (它没有帮助):

代码语言:javascript
复制
const PORT = process.env.PORT || 443

app.listen(PORT, () => {
    console.log(`Server stated on port ${PORT}`)
})

在我的本地机器上,我使用5000端口,并通过"http://locahost:5000“访问应用程序(它工作得很好)。

"/etc/apache2/sites-available/my-site-api.conf":

代码语言:javascript
复制
<VirtualHost *:80>
    ServerName api.mysite.com
    ServerAlias api.mysite.com
    DocumentRoot /var/www/mysite/api
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =api.mysite.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

"/etc/apache2/sites-available/my-site-api-le-ssl.conf":

代码语言:javascript
复制
<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName api.mysite.com
        ServerAlias api.mysite.com
        DocumentRoot /var/www/mysite/api
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        RewriteEngine on
        # Some rewrite rules in this file were disabled on your HTTPS site,
        # because they have the potential to create redirection loops.
        
        # RewriteCond %{SERVER_NAME} =api.mysite.com [OR]
        # RewriteCond %{SERVER_NAME} =api.mysite.com
        # RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/api.mysite.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/api.mysite.com/privkey.pem
    </VirtualHost>
</IfModule>

如果你需要任何其他信息,请告诉我。

提前谢谢你!

EN

回答 1

Stack Overflow用户

发布于 2020-07-19 14:18:28

看起来Apache和你的应用都被配置为侦听端口443。我假设您得到的本质错误是每个端口应该只有一个监听程序,并且它告诉您443已经被apache占用。

如果你想在HTTPS/443下公开你的应用程序,我有两种方法

  1. 将Apache设置为代理,以便它侦听443并将请求转发到您的应用程序(它应该会继续侦听5000个)。这将需要在Apache配置中添加如下内容:

代码语言:javascript
复制
ProxyPass "/" "http://localhost:5000"

  1. 避免使用Apache,直接在https下暴露你的应用。在这种情况下,您必须为您的应用程序初始化提供参数,告诉您在哪里可以找到证书,并且您必须以超级用户身份运行您的应用程序。

更多详细信息请访问:Enabling HTTPS on express.js

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62976872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档