Apache多端口HTTPS

时间:2019-05-21 19:29:54

标签: apache https proxy bitnami

我的配置

  • 使用Bitnami的AWS Lightsail
  • 反应在端口3000上运行
  • Express在端口3001上运行
  • 使用Bitnami脚本的HTTPS(使用“让我们加密”)

我想要的东西

  1. 来自https://www.ipos.fun/https://ipos.fun/ipos.fun/www.ipos.fun/的任何呼叫都转到https://www.ipos.fun/。 (添加wwww + https)
  2. 端口3001上的我的Express API也可以用于HTTPS。

目前正在做什么

  1. 所有前端重定向工作正常。

什么不起作用

  1. 我的Express API通过HTTP运行,但是尝试访问https://www.ipos.fun:3001/时出现错误www.ipos.fun unexpectedly closed the connection.

我尝试过的

请在下面找到我的所有配置,但我认为重要的是:

ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

我想根据端口号进行匹配,但是似乎没有任何作用。 我还尝试了以下URL https://www.ipos.fun:3001/api/

ProxyPass /api http://localhost:3001/
ProxyPassReverse /api http://localhost:3001/

我试图创建多个VirtualHost来对端口号进行模式匹配,但是它不起作用。

问题

如何使我的Express API兼容3001 HTTPS端口?

这是我的配置:

# Default Virtual Host configuration.

<IfVersion < 2.3 >
  NameVirtualHost *:80
  NameVirtualHost *:443
</IfVersion>


<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  RewriteEngine On
  # BEGIN: Enable HTTP to HTTPS redirection
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
  # END: Enable HTTP to HTTPS redirection
  # BEGIN: Enable non-www to www redirection
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>

# Default SSL Virtual Host configuration.

<IfModule !ssl_module>
  LoadModule ssl_module modules/mod_ssl.so
</IfModule>

Listen 443
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "..."
SSLPassPhraseDialog  builtin
SSLSessionCache "shmcb:/opt/bitnami/apache2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  RewriteEngine On
  # BEGIN: Enable non-www to www redirection
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
  SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/ipos.fun.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/ipos.fun.key"

  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

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


    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/


  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>

# Bitnami applications that uses virtual host configuration
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf"

1 个答案:

答案 0 :(得分:0)

一种解决方案是在VirtualHost中添加路由:443,

ProxyPass /api/ http://localhost:3001/
ProxyPassReverse /api/ http://localhost:3001/

这是我之前提到的,我只是在端口3001而不是端口HTTPS 443上进行测试。