如何使用let加密设置Openshift(letsencrypt)

Bre*_*ght 17 openshift lets-encrypt

如何设置Openshift应用程序以使用let加密?

NB Openshift无法使用简单的python webserver方法处理服务器,您需要使用正确的端口并绑定到正确的IP地址.app/gear也没有必要有html root.

(我将在下面发布答案的问题.)

Luc*_*s03 13

首先,在这里投票,以便OpenShift将"Let's Encrypt"作为他们的首要任务.

我的步骤对Django应用程序有效,但只需稍加修改就可以使它们适用于任何OpenShift设备.
在localhost/notebook/pc上生成证书:

  1. git clone https://github.com/letsencrypt/letsencrypt 到你的本地电脑.
  2. cd letsencrypt
  3. ./letsencrypt-auto -a manual -d example.com -d www.example.com
    现在,系统会要求您确认域名所有权.
  4. 在您的应用中,确保example.com/.well-known/acme-challenge/{some hash}返回所需的哈希值.在django中,您可以将此行添加到urls.py:

    url(r'^.well-known/acme-challenge/.*', views.https_confirmation, name="https_confirmation"),
    
    Run Code Online (Sandbox Code Playgroud)

    这个view.py:

    def https_confirmation(request):
        if request.META['HTTP_HOST'] == 'www.example.com':
            return HttpResponse("fqTGI3nUiYnelm...", content_type="text/plain")
        else: #naked domain example.com
            return HttpResponse("HASH pre example.com", content_type="text/plain")
    
    Run Code Online (Sandbox Code Playgroud)

    如果您的极限确认页面未显示,请重新启动OpenShift应用程序.

  5. 只需将创建的证书上传/etc/letsencrypt/archive/example.com到OpenShift Web控制台即可.Fullchain.pem作为SSL证书,privkey.pem作为证书私钥.

就是这样,现在你应该在ssllabs.com上获得A评级.
此外,要求Django应用程序使用HTTPS,请设置以下内容:

  1. settings.py:

    if not DEBUG:
        SESSION_COOKIE_SECURE = True
        CSRF_COOKIE_SECURE = True`
    
    Run Code Online (Sandbox Code Playgroud)
  2. 创建文件wsgi/.htaccess并将这些行放在那里:

    RewriteEngine on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    
    Run Code Online (Sandbox Code Playgroud)
  3. 为WSGI启用HTTPS - 在文件中wsgi/application:

    # make django aware that SSL is turned on
    os.environ['HTTPS'] = "on"
    
    Run Code Online (Sandbox Code Playgroud)

    这应该是全部:)你需要在更新证书时重复这些步骤,所以每90天(60天更好,所以你不会在最后一天遇到问题).这是非常烦人的步骤,所以让希望(和投票)OpenShift很快就会实现Letsencrypt!


Bre*_*ght 3

假设应用程序名为https,证书的域名名为www.example.com

首先(如果尚未完成)安装 rhc 工具,https://developers.openshift.com/en/managing-client-tools.html

其次(如果尚未完成)使用您的 DNS 提供商设置 CNAME 记录 - 在developers.openshift.com/en/managing-domains-ssl.html 测试 www.example.com (http) 是否正常工作并定向到您的 openshift 应用程序前。

第三次 登录您的应用程序

rhc ssh -a https
Run Code Online (Sandbox Code Playgroud)

从应用程序中,安装 Simple Let's Encrypt Client 并更新所需的一些 python 包

pip install git+https://github.com/kuba/simp_le
pip install --upgrade six
pip install --upgrade setuptools
Run Code Online (Sandbox Code Playgroud)

现在停止应用程序 (gear) 设置一个 python2 网络服务器,具有正确的端口和正确的 IP。[$OPENSHIFT_PYTHON_IP 和 OPENSHIFT_PYTHON_PORT]

(请注意,这是 python 3.4 中的一行, python -m http.server $OPENSHIFT_PYTHON_PORT --bind $OPENSHIFT_PYTHON_IP 但在撰写本文时 openshift 只有 python 3.2 或 python 2。因此需要一个简单的 python 17 行脚本)

gear stop
mkdir -p /tmp/http/.well-known/acme-challenge
cd /tmp/http
wget https://gist.githubusercontent.com/bmsleight/bc34254eed0ee458738e/raw/61110fe6e3980f0c6a401acae93f221f56b1eced/simple_acme_server.py
python2 simple_acme_server.py &
Run Code Online (Sandbox Code Playgroud)

转到数据目录作为存储证书的好地方,让 simp_le 发挥其魔力

cd ~/app-root/data/
simp_le --email example@example.com -f account_key.json   -f fullchain.pem -f key.pem   -d www.example.com --default_root /tmp/http 
Run Code Online (Sandbox Code Playgroud)

假设没有错误,停止 python2 web 服务器,重新启动应用程序/gear 并退出 openshift 服务器

killall python2
gear start
exit
Run Code Online (Sandbox Code Playgroud)

第四 证书和密钥的上传必须在应用程序外部完成,因此从本地计算机获取副本然后上传它们(是的 scp 是错误的方式 - RTFM)

rhc scp -a https download ./ ./app-root/data/fullchain.pem
rhc scp -a https download ./ ./app-root/data/key.pem
rhc alias update-cert https www.example.com --certificate fullchain.pem --private-key key.pem
Run Code Online (Sandbox Code Playgroud)

第五 在 LetsEncrypt.org 表达一些爱

  • 很好的答案,但我认为对具有不同名称的应用程序执行此操作会更清楚。将您的应用程序命名为 https 并使用 https 协议会造成不必要的混乱。 (3认同)