首页 > 解决方案 > 如何配置 apache 将 https 请求转发到在端口 1337 上运行的 Strapi/node 应用程序?

问题描述

我有一个 Strapi/node js 应用程序在端口 1337 上运行,我可以通过以下方式访问它:

http://my-ip:1337

我还在同一服务器中关联了一个域,并在 apache2 中有一个有效的 ssl 证书,因此在浏览器中我可以使用 https:

https://my-domain.com

现在,当我尝试使用 https 访问端口 1337 时,如下所示:

https://my-domain.com:1337

我收到“此站点无法提供安全连接”错误。

我尝试使用以下代码在 apache 2 中编辑 my-domain.ssl.conf:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName www.my-domain
        ServerAlias my-domain
        DocumentRoot /var/www/my-domain/public_html
        ErrorLog /var/www/my-domain/log/error.log
        CustomLog /var/www/my-domain/log/requests.log combined

        SSLProxyEngine On
        ProxyPreserveHost On

        ProxyPass / http://localhost:1337/
        ProxyPassReverse / http://localhost:1337/

        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/my-domain/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/my-domain/privkey.pem
    </VirtualHost>
</IfModule>

但不幸的是,当我引入 ProxyPass 指令时,服务器停止工作而没有任何有意义的错误。mod_proxy 和 mod_proxy_http 都加载在 apache2 配置中。

这里可能是什么问题?感谢任何可以帮助它的人!

标签: node.jssslhttpsapache2proxypass

解决方案


Strapi/node js 应用程序在端口 1337 上运行到 https

第一次变化

编辑 /etc/apache2/sites-available/000-default.conf

  ServerName yourdomian-name.com
  ProxyPreserveHost On
  SSLProxyEngine On
  ProxyPass / http://localhost:1337/
  ProxyPassReverse / http://localhost:1337/
  ProxyPreserveHost On


  SSLCertificateFile /etc/letsencrypt/live/yourdomian-name.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/yourdomian-name.com/privkey.pem

第二次改变

编辑这个 /etc/apache2/sites-available/000-default-le-ssl.conf

    SSLCertificateFile /etc/letsencrypt/live/yourdomian-name.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/yourdomian-name.com/privkey.pem
    ServerName yourdomian-name.com
    ProxyPreserveHost On
    SSLProxyEngine On
    ProxyPass / http://localhost:1337/
    ProxyPassReverse / http://localhost:1337/
    ProxyPreserveHost On

然后重启apache2

须藤 /etc/init.d/apache2 重启

检查https://yourdomian-name.com


推荐阅读