首页 > 解决方案 > 如何为 http 和 https 使用相同的端口

问题描述

我几乎不知道 http 和这个主题,所以找不到任何足以解决我的问题的答案。让我知道这个问题是否重复并且您已经找到了有关此问题的答案。

我想要达到的目标

通常它与http://domain:3000一起使用,但我想让它可以访问https://domain:3000

我做了什么

我安装了 let's encrypt 并在我的 apache 设置文件中添加了反向代理设置。因此可以使用https: //domain/api等路径访问https://domain:3000 ,但正如我上面提到的,我也想直接在 https 上使用端口号。

我的 httpd.conf 上的其他行是

NameVirtualHost *:80
<VirtualHost *:80>
     ServerName my.domain
     ServerAlias www.my.domain *.my.domain
     DocumentRoot /var/www/html
     RewriteEngine on
     RewriteCond %{SERVER_NAME} =my.domain [OR]
     RewriteCond %{SERVER_NAME} =www.my.domain [OR]
     RewriteCond %{SERVER_NAME} =*.my.domain
     RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
     Listen 443
</IfModule>
Include /etc/httpd/conf/httpd-le-ssl.conf

<IfModule mod_proxy.c>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass /api http://my.domain:3000
    ProxyPassReverse /api http://my.domain:3000
</IfModule>

我需要添加更多设置吗?或任何其他方式来解决这个问题?

标签: apachehttpsport

解决方案


最好配置您必须使用不同端口进行 SSL 连接的应用程序,例如 3001 并通过 HTTPS 将请求转发到此端口或直接访问它


推荐阅读