我有一个在端口 1337 上运行的 Strapi/node js 应用程序,我可以通过以下方式访问它:
http://我的IP:1337
我还在同一服务器中关联了一个域,并在 apache2 中拥有一个工作 ssl 证书,以便在浏览器中我可以使用 https:
现在,当我尝试使用 https 访问端口 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 配置中..
这可能是什么问题?感谢任何可以帮忙的人!!
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
sudo /etc/init.d/apache2 restart
您只需更改
yourdomain-le-ssl.conf
并启用模块(如果没有)。
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo systemctl restart apache2
<VirtualHost *:443>
ServerName yourdomain.com
SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private-key.key
SSLCertificateChainFile /path/to/your/chain-file.pem
#This is important
<Location "/">
ProxyPass "http://127.0.0.1:1337/"
ProxyPassReverse "http://127.0.0.1:1337/"
</Location>
ErrorLog ${APACHE_LOG_DIR}/yourdomain-error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain-access.log combined
</VirtualHost>
就是这样。现在只需重新启动 Apache。
sudo systemctl restart apache2