【问题标题】:Apache multiple ports HTTPSApache 多端口 HTTPS
【发布时间】:2019-05-21 19:29:54
【问题描述】:

我的配置

  • 使用 Bitnami 的 AWS Lightsail
  • React 在 3000 端口上运行
  • Express 在 3001 端口上运行
  • HTTPS 使用 Bitnami 脚本(使用 Let's encrypt)

我想要什么

  1. 来自https://www.ipos.fun/https://ipos.fun/ipos.fun/www.ipos.fun/ 的任何呼叫转至https://www.ipos.fun/。 (添加 wwww + https)
  2. 我的 Express API 在端口 3001 上也可以使用 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/

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

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

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

问题

如何使我在端口 3001 上的 Express API 兼容 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"

【问题讨论】:

    标签: apache https proxy bitnami


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-09-15
      • 2016-01-17
      • 2013-10-29
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      • 2020-04-15
      • 2017-09-07
      • 1970-01-01
      相关资源
      最近更新 更多