在NGINX / Ubuntu 16.1 x64(Digital Ocean)上安装SSL证书



我一直在尝试在Digital Ocean上的droplet上安装RapidSSL证书。这个液滴运行的是NGINX/Ubuntu 16.1 x64。

我正在遵循本教程: https://www.digitalocean.com/community/tutorials/how-to-install-an-ssl-certificate-from-a-commercial-certificate-authority#install-certificate-on-web-server

但是我到了需要编辑"Nginx服务器块"的部分:

Now go to your Nginx server block configuration directory. Assuming that 
is located at /etc/nginx/sites-enabled, use this command to change to it:
cd /etc/nginx/sites-enabled
Assuming want to add SSL to your default server block file, open the file 
for editing:
sudo vi default
Find and modify the listen directive, and modify it so it looks like this:
listen 443 ssl; 
Then find the server_name directive, and make sure that its value matches 
the common name of your certificate. Also, add the ssl_certificate and 
ssl_certificate_key directives to specify the paths of your certificate 
and private key files (replace the highlighted part with the actual path 
of your files):
server_name example.com;
ssl_certificate /home/sammy/example.com.chained.crt;
ssl_certificate_key /home/sammy/example.com.key;
To allow only the most secure SSL protocols and ciphers, add the following 
lines to the file:
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

"Sudo vi default"是一个空文件。那么我需要在哪里编辑文件? Nginx config?

我有:

/etc/nginx/nginx.conf

/etc/nginx/sites-available/nginxconfig

/etc/nginx/sites-enabled/nginxconfig

/home/user/user/deploy/nginxconfig

那么我需要编辑哪个文件?我真的很困惑..任何错误都可能因破坏我的网站而告终

编辑此文件(您会注意到您的/站点启用/是符号链接)

vi /etc/nginx/sites-available/nginxconfig

查找上面文件提及的位置ssl_ciphers就在该行上方添加行

ssl_certificate     /full/path/to/reach/file/fullchain.pem;
ssl_certificate_key /full/path/to/reach/file/privkey.pem;

一个正确的TLS nginx配置有许多其他设置,这些设置对安全站点至关重要......我建议你启动一个开发数字海洋液滴进行编辑......以及额外的测试 TLS 证书以匹配您的开发框的 DNS 地址......还可以从letscrypt获得免费的TLS证书,只需每3个月启用一次自动刷新即可正常工作。

Mozilla的好心人做了一个nginx配置生成器

https://mozilla.github.io/server-side-tls/ssl-config-generator/

你指定nginx的版本,它给你一个工作配置文件

以下是在 ubuntu 上为 nginx Web 服务器安装免费 SSL 时需要遵循的步骤。 第 1 步。使用SSH登录到云VPS服务器

如果您使用的是 windows,请下载 putty 并使用 root 用户和密码登录。

第 2 步。将您的域名指向云VPS的IP地址

登录到您的域名注册商并更改域"A"记录以指向您的云托管VPS或托管服务器的IP地址。

更改 Godaddy 帐户中的 DNS A 记录 第3步。创建或配置 Nginx 服务器块以托管多个网站(类似于 Apache 中的虚拟主机)

首先,创建存储网站文件的文档根目录或文件夹。键入以下命令。

sudo mkdir -p/var/www/domain.com/html 现在,为您托管或尝试为其安装 SSL 证书的域创建服务器块。如果您的网站已经在运行,则应跳过此步骤。但是,如果您是第一次在新的云 VPS 上托管网站,则必须为要托管的每个网站创建一个单独的服务器块。

sudo nano/etc/nginx/conf.d/domain.com.conf 然后,将以下服务器块模板粘贴到文件中,确保将域名更改为您的域名。

服务器 { 听80;

# just Change the domain name in red
server_name domain.com www.domain.com;
root /var/www/domain.com/html;
index index.php index.html index.htm;
access_log /var/log/nginx/http_access.log combined;
error_log /var/log/nginx/http_error.log;
location / {
try_files $uri $uri/ =404;  
}       
# set long EXPIRES header on static assets
location ~* .(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
access_log off;
}

} 最后,重新启动 Nginx 服务器以使更改生效。

sudo systemctl restart nginx 第4步。安装和设置免费的 SSL 证书

键入以下命令以启动 SSL 安装:

sudo apt-get 更新 sudo apt-get install software-properties-common sudo add-apt-repository ppa:certbot/certbot sudo apt-get 更新 sudo apt-get install python-certbot-nginx 键入以下命令,为在此服务器上托管的所有域或网站获取并安装 SSL 证书。添加 -dargument,后跟每个域名及其别名,并在单个命令中添加任意数量的域。

sudo certbot --nginx -d domain.com -d www.domain.com 第5步。验证让我们加密 SSL 证书续订 我已经分享了原始源链接,从那里您可以获得有关如何在单个云 VPS 上托管多个网站的完整分步指南,然后在 Ubuntu 上为 Nginx Web 服务器安装免费 SSL。

试运行以下命令以测试是否正确设置了自动续订。

须藤塞特机器人更新 --干运行

如果您没有足够的时间阅读,或者您更喜欢观看而不是阅读,那么这里是视频链接。

有关如何使用 Ubuntu 在 Nginx Web 服务器上安装免费 SSL 并在单个云 VPS 上托管多个网站的详细信息指南,您可以访问 hawkdive 上的链接:https://www.hawkdive.com/install-free-ssl-for-nginx-web-server-on-ubuntu-16-04-or-ubuntu18-04/

https://www.youtube.com/watch?v=1Un0v4dUTy0&feature=youtu.be

最新更新