首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在NGINX /Ubuntu16.1 x64 (数字海洋)上安装SSL证书

在NGINX /Ubuntu16.1 x64 (数字海洋)上安装SSL证书
EN

Stack Overflow用户
提问于 2018-01-15 18:03:49
回答 2查看 1.9K关注 0票数 2

我一直在尝试在我的droplet on Digital Ocean上安装RapidSSL证书。这个droplet正在运行NGINX /Ubuntu16.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 server block“的地方:

代码语言:javascript
复制
  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配置?

我有:

/etc/nginx/nginx.conf

/etc/nginx/sites available/nginxconfig

/etc/nginx/sites enabled/nginxconfig

/home/user/user/deploy/nginxconfig

那么我需要编辑哪个文件呢?我真的很困惑..。任何错误都可能以破坏我的站点而结束

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-01-16 03:53:20

编辑此文件(您将注意到您的/sites enabled/是sym链接)

代码语言:javascript
复制
vi /etc/nginx/sites-available/nginxconfig

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

代码语言:javascript
复制
ssl_certificate     /full/path/to/reach/file/fullchain.pem;
ssl_certificate_key /full/path/to/reach/file/privkey.pem;

一个正确的TLS nginx配置有许多其他设置,这些设置对安全站点至关重要……我建议你打开一个dev digitalocean水滴来进行编辑...以及一个额外的测试TLS证书以匹配您的开发箱的DNS地址...还可以从letsencrypt获得免费的TLS证书,它工作得很好,只需要每3个月自动刷新一次。

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

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

在其中指定nginx的哪个版本,它会给出一个有效的配置文件

票数 2
EN

Stack Overflow用户

发布于 2019-01-22 21:59:24

以下是在ubuntu上为nginx web服务器安装免费ssl所需的步骤。步骤1.使用SSH登录云VPS服务器

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

步骤2.将您的域名指向Cloud VPS的IP地址

登录到您的域注册商,并更改域‘A’记录,以指向您的云主机VPS或主机服务器的IP地址。

3.创建或配置Nginx Server Block以托管多个网站(类似于Apache中的虚拟主机)

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

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

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

服务器{监听80;

代码语言:javascript
复制
# 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重启nginx步骤4.安装和设置免费SSL证书

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

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

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

dry运行以下命令,测试自动续费设置是否正确。

sudo certbot续订--预演

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

有关如何在带有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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48260675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档