使用letencrypt和apache2在KeystoneJS上使用SSL

时间:2018-09-11 14:03:03

标签: node.js express apache2 lets-encrypt keystonejs

我正在使用docker-compose在Ubuntu 16上部署keystonejs应用,并拥有有效的letencrypt证书。

我在keystone.js中添加了以下设置

'ssl': true
'port': 3000,
    'admin path': 'admin',
    'ssl cert': '/etc/letsencrypt/live/mydomain.com/fullchain.pem',
    'ssl key': '/etc/letsencrypt/live/mydomain.com/privkey.pem',
    'letsencrypt': (process.env.NODE_ENV === 'production') && {
        email: 'user@gmail.com',
        domains: ['www.mydomain.com', 'mydomain.com'],
        register: true,
        tos: true,
    },

服务器开始向我显示以下内容:

app |
app | ------------------------------------------------
app | KeystoneJS v4.0.0 started:
app | mydomain is ready on http://0.0.0.0:3000
app | SSL Server is ready on https://0.0.0.0:3001
app | ------------------------------------------------
app |

但是当我访问我的网站时。它不会从浏览器的url选项卡中显示为受保护。它显示了一个感叹号(!)。说:您与该站点的连接不安全。

我的服务器上有apache2。

在/etc/apache2/sites-available/mydomain.com.conf下的

我有这个:

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin info@mydomain.com
  ServerName  mydomain.com
  ServerAlias www.mydomain.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html
  DocumentRoot /var/www/html/mydomain.com/
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/mydomain.com/log/error.log
  CustomLog /var/www/html/mydomain.com/log/access.log combined

ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost On

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

以及/etc/apache2/sites-available/mydomain.com.le.ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin info@mydomain.com
  ServerName  mydomain.com
  ServerAlias www.mydomain.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html
  DocumentRoot /var/www/html/mydomain.com/
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/mydomain.com/log/error.log
  CustomLog /var/www/html/mydomain.com/log/access.log combined

ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost On

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

我尝试将ProxyPass和ProxyPassReverse指向3001端口。但是该站点将永远无法访问。 非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

尝试在梯形失真校正中禁用SSL。通过Apache服务器代理流量时,您不需要它。它将处理证书,并在没有SSL的情况下在本地与Keystone通信。然后,您可以阻止3000端口从外部访问bee。