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

时间:2017-08-17 10:29:35

标签: nginx vps lets-encrypt gogs

我在tuto(https://gogs.io/docs/installation/install_from_source)的帮助下在GPS上安装了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配置,我做了,尽管我有一个反向代理(可能问题在这里)。 / p>

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;
    }
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您将所有请求代理到http://localhost:port_number,但此程序可能不知道如何处理let-encrypt请求。

相反,您应该将.well已知位置更改为:

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

当certbot要求您提供webroot时,您可以回答/var/www/letsencrypt

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

读取