在 Debian 9 中使用 Nginx for Gogs 启用 Letsencrypt



我刚刚在tuto(https://gogs.io/docs/installation/install_from_source(的帮助下在VPS上安装了Gogs。 我有一个子域可以访问我的 gogs 实例:git.mydomainname.com 并且它有效:http://git.mydomainname.com 使用反向代理转到我的 gogs 实例。

我想通过SSL保护我的gogs,所以我想使用以下tuto(https://certbot.eff.org/#debianstretch-nginx(安装LetsEncrypt。

我想说的是,我是系统管理的新手,不一定了解我在Gogs安装过程中所做的一切。 我也是Nginx的新手(更习惯于Apache(。

这是我遵循的过程:

$ sudo certbot certonly
Saving debug log to /var/log/letsencrypt/letsencrypt.log
How would you like to authenticate with the ACME CA?
-------------------------------------------------------------------------------
1: Place files in webroot directory (webroot)
2: Spin up a temporary webserver (standalone)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel):git.mydomainname.com
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for git.mydomainname.com
Select the webroot for git.mydomainname.com:
-------------------------------------------------------------------------------
1: Enter a new webroot
-------------------------------------------------------------------------------
Press 1 [enter] to confirm the selection (press 'c' to cancel): /home/git/go/src/github.com/gogits/gogs
** Invalid input **
Press 1 [enter] to confirm the selection (press 'c' to cancel): 1
Input the webroot for git.mydomainname.com: (Enter 'c' to cancel):/home/git/go/src/github.com/gogits/gogs
Waiting for verification...
Cleaning up challenges
Failed authorization procedure. git.mydomainname.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://git.mydomainname.com/.well-known/acme-challenge/N4rMGzoq1Bwyt9MP9fUlVY3_mDnJfRYpQkdvc7WrNJs: "<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>"
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: git.mydomainname.com
Type:   unauthorized
Detail: Invalid response from
http://git.mydomainname.com/.well-known/acme-challenge/N4rMGzoq1Bwyt9MP9fUlVY3_mDnJfRYpQkdvc7WrNJs:
"<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>"
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A record(s) for that domain
contain(s) the right IP address.

所以我检查了错误,DNS A 记录正常。 我还找到了另一个法语 (https://www.grafikart.fr/formations/serveur-linux/nginx-ssl-letsencrypt( 的 tuto 来帮助我,我注意到我必须为网站更新我的 nginx 配置,尽管我有一个反向代理(也许问题在这里(。

server {
listen 80;
server_name git.mydomainname.com
location ~ /.well-known/acme-challenge {
allow all;
}
location ~ /. {
deny all;
access_log off;
log_not_found off;
}
location / {
proxy_pass http://localhost:port_number;
}
}

感谢您的帮助。

你正在将所有请求代理到 http://localhost:port_number,但这个程序可能不知道如何处理 lets-encrypt 请求。

相反,您应该将 .good 位置更改为:

location ^~ /.well-known/acme-challenge/ {
allow all;
root /var/www/letsencrypt;
}

当 certbot 要求您提供网络根目录时,您可以回答/var/www/letsencrypt

注意:您可以将/var/www/letsencrypt更改为所需的任何目录。它只需要先创建,并可由您的nginx用户读取

最新更新