nginx配置Let’s Encrypt最新教程

nginx配置Let’s Encrypt最新教程,Let’s Encrypt是一个证书颁发机构Certificate Authority (CA) ,它提供免费的TLS / SSL证书以在Web服务器上启用HTTPS。这篇文章是关于服务器配置教程的分享。

nginx配置Let's Encrypt最新教程
nginx配置Let's Encrypt最新教程 4

Let’s Encrypt介绍

Let’s Encrypt是一个证书颁发机构Certificate Authority (CA) ,它提供免费的TLS / SSL证书以在Web服务器上启用HTTPS。他们提供了一个称为Certbot的软件客户端,可以自动执行获取证书并在Nginx Web服务器中进行配置所需的大多数步骤。

nginx配置Let’s Encrypt要求

  • 您已经配置了SSH密钥
  • 您有一个指向您的Web服务器的注册域名
  • 您有一个在国外VPS上运行的网站

安装NGINX Web服务器

1。root通过SSH连接到服务器。

2。更新APT数据包缓存和实例上已安装的软件:

apt update && apt upgrade -y

3。通过APT 安装Nginx Web服务器:

apt install nginx -y

配置服务器块

Nginx在Ubuntu Bionic Beaver上的默认安装附带一个预定义的服务器块,该服务器块侦听端口80。虽然可以通过将内容放入目录/ var / www / html来承载单个站点,但不会可以在同一实例中托管多个站点。为避免此问题,可以配置服务器块。它们为请求特定站点时将要提供的内容指定目录。的内容的/var/ www/html等将担任默认目录,如果请求不符合配置的任何其他网站。

重要提示:在本教程中,将使用域名jhrs.com。在设置实例时,应使用自己的域名替换它。

1。为您的域名创建目录。如果该-p标志不存在,则使用该标志将创建任何必需的父目录:

mkdir -p /var/www/jhrs.com/html

2。创建一个占位符页面,该页面将在访问您的域时显示:

nano /var/www/jhrs.com/html/index.html

3。将类似以下内容的文件放入文件中,该文件将在请求您的网站时显示给用户。编辑文件后,保存并退出nano:

<html>
    <head>
        <title>Welcome to jhrs.com</title>
    </head>
    <body>
        <h1>Hello World!</h1>
        <p>You have accessed the jhrs.com website.</p>
    </body>
</html>

4。要为站点提供服务,需要一个服务器块。在目录/ etc / nginx / sites-available /中创建块:

nano /etc/nginx/sites-available/jhrs.com

并将以下内容放入其中:

server {
        listen 80;
        listen [::]:80;

        root /var/www/jhrs.com/html;
        index index.html index.htm;

        server_name example.com www.jhrs.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

重要提示:编辑线root,并server_name根据您的域名。

5。通过将文件链接到启用站点的目录来启用文件,以在Nginx启动期间启用服务器块:

ln -s /etc/nginx/sites-available/jhrs.com /etc/nginx/sites-enabled/

6。重新启动Nginx之前,请验证配置文件中是否没有错误:

nginx -t

7。重新启动Nginx Web服务器:

systemctl restart nginx

8。在浏览器中输入https://jhrs.com时,您应该看到新创建的占位符页面:

example.com网站

安装Certbot并获取证书

1。Certbot正在积极开发中,Ubuntu中包含的软件包可能已经过时了。因此,添加Certbot存储库以使其易于下载该软件的最新版本:

add-apt-repository ppa:certbot/certbot

当要求确认操作时,按Enter键

2。为Nginx安装Certbot:

apt install python-certbot-nginx -y

3。启动证书生成:

certbot --nginx -d example.com -d www.jhrs.com

要点:该参数-d指定要为其请求证书的域。确保将其替换为您自己的域名。另外请记住,如果要为jhrs.comwww.jhrs.com拥有证书,则必须同时指定两者。

首次运行Certbot时,将要求您输入电子邮件地址。通过按键盘上的Enter确认。

4。确认后,Certbot将进行质询并请求证书。当要求将所有流量重定向到HTTPS时,请按2,然后键盘上的Enter键:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

Certbot现在将重新配置Nginx,并且当您看到以下消息时,您的证书已成功安装:

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/jhrs.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/jhrs.com/privkey.pem
   Your cert will expire on 2019-04-15. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

现在,您可以打开Web浏览器来验证nginx配置Let’s Encrypt是否成功,然后输入https://jhrs.com来验证您的连接是否安全:

nginx配置Let's Encrypt
nginx配置Let’s Encrypt

至此,nginx配置Let’s Encrypt已经完毕。

猜你喜欢

本站最新优惠

Namesilo优惠:新用户省 $1 域名注册-优惠码:45D%UYTcxYuCloZ 国外最便宜域名!点击了解更多

特别优惠:免费赠送 $100 Vultr主机-限时优惠!英文站必备海外服务器!点击了解更多

VPS优惠:搬瓦工优惠码:BWH3OGRI2BMW 最高省5.83%打开外面世界的一款主机点击了解更多

加入电报群

【江湖人士】(jhrs.com)原创文章,作者:江小编,如若转载,请注明出处:https://jhrs.com/2020/37905.html

扫码加入电报群,让你获得国外网赚一手信息。

文章标题:nginx配置Let’s Encrypt最新教程

(0)
江小编的头像江小编
上一篇 2020-08-16 10:36
下一篇 2020-08-23 17:13

热门推荐

发表回复

登录后才能评论
国外老牌便宜域名服务商Namecheap注册com域名大优惠,抢到就赚到,优惠码:NEWCOM698
$5.98/年
直达官网