2017-08-17 101 views
0

我刚刚在tps(https://gogs.io/docs/installation/install_from_source)的帮助下在VPS上安装了Gogs。 我有一个子域,以达到我的gogs实例:git.mydomainname.com,它的工作原理:http://git.mydomainname.com去我的gogs实例与反向代理。使用Nginx for Gogs在Debian 9中启用Letsencrypt

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

我想说我是系统管理的新手,并不一定了解我在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记录是OK。 我还发现法语(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; 
    } 
} 

感谢您的帮助。

+0

尝试'2:启动一个临时webserver(独立)'而不是webroot。 – tkausl

回答

0

您正在将您的所有请求转发到http://localhost:port_number,但该程序可能不知道如何处理让加密请求。

相反,你应该改变你。好了著名的位置:

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

而当certbot问你一个根目录,你可以回答/var/www/letsencrypt

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