【发布时间】:2019-06-29 14:51:52
【问题描述】:
我已经使用这篇文章在我的 Centos7 VPS (DirectAdmin) 上设置了一个 Omnibus Gitlab 服务器: how to install gitlab on a directadmin server
它对 HTTP 请求非常有效。 出于安全原因,我想在 GitLab 子域 gitlab.domain.com 上设置 HTTPS。 我想使用 LetsEncrypt 免费的 SSL 证书。问题是 LetsEncrypt 无法使用 Certbot 验证我的域: certbot certonly --webroot --webroot-path=/var/www/letsencrypt -d gitlab.domain.com
输出失败:
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: gitlab.domain.com
Type: unauthorized
Detail: Invalid response from
http://gitlab.domain.com/.well-known/acme-challenge/8Xj5vc-KMfhHYgH7PhXCFEetcxzQBDk-puiA2tRfoB4:
"<!DOCTYPE html>\n<html class=\"devise-layout-html\">\n<head
prefix=\"og: http://ogp.me/ns#\">\n<meta charset=\"utf-8\">\n<meta
content=\"IE"
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address.
我搜索了一下,似乎 LetsEncrypt 必须到达文件夹路径:
http://gitlab.domain.com/.well-known/acme-challenge/xxxxxxxxxx
所以我创建了路径并授予 777 权限,并出于测试目的在其中放置了一个 test.html。 现在我可以使用 HTTP 访问文件,但无法使用 HTTPS 访问它。
curl -I -k https://gitlab.domain.com/.well-known/acme-challenge/test.html
输出:
HTTP/1.1 301 Moved Permanently
Date: Wed, 06 Feb 2019 10:05:40 GMT
Server: Apache/2
Location: http://gitlab.domain.com/.well-known/acme-challenge/test.html
Content-Type: text/html; charset=iso-8859-1
我已经在服务器上安装了 DirectAdmin,但我不知道如何自定义子域的 HTTPD.conf 文件以便一切正常。
直接管理员的自定义 HTTPD.conf 部分:
ServerName gitlab.domain.com
ServerSignature Off
ProxyPreserveHost On
# Ensure that encoded slashes are not decoded but left in their encoded state.
# http://doc.gitlab.com/ce/api/projects.html#get-single-project
AllowEncodedSlashes NoDecode
<Location />
Order deny,allow
Allow from all
#Allow forwarding to gitlab-workhorse
ProxyPassReverse http://127.0.0.1:8181
ProxyPassReverse http://gitlab.domain.com/
</Location>
# Apache equivalent of nginx try files
# http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
# http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
RewriteEngine on
# Forward all requests to gitlab-workhorse except existing files like error documents
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} ^/uploads/.* [NC,OR]
RewriteCond %{REQUEST_URI} !^.*/\.well-known/acme-challenge/.*$ [NC]
RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
Alias /.well-known/acme-challenge/ /var/www/letsencrypt/
<Directory "/var/www/letsencrypt/">
Order allow,deny
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Allow from all
</Directory>
# needed for downloading attachments
DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
值得一提的是,使用带有 HTTP-01 和 DNS-01 方法的 https://letsdebug.net/ 测试我的域返回一切正常。
我认为如果我可以处理 HTTPS 请求以保证 LetsEncrypt API 通过 HTTP 和 HTTPS 访问http://gitlab.domain.com/.well-known/acme-challenge/ URL,那就没问题了。
【问题讨论】:
标签: gitlab centos7 httpd.conf directadmin