在NGINX / Ubuntu 16.1 x64(数字海洋)

时间:2018-01-15 10:03:49

标签: ubuntu nginx https ssl-certificate

我一直在尝试在Digital Ocean上的Droplet上安装RapidSSL证书。此Droplet正在运行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默认"是一个空文件。那么我需要编辑文件? Nginx配置?

我有:

/etc/nginx/nginx.conf

的/ etc / nginx的/位点可用/ nginxconfig

的/ etc / nginx的/ / nginxconfig启用位点-

/家庭/用户/用户/部署/ nginxconfig

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

2 个答案:

答案 0 :(得分:2)

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

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配置有许多其他设置对安全站点至关重要...我建议你启动一个dev digitalocean droplet来进行编辑......以及一个额外的测试TLS证书来匹配DNS地址您的开发箱...也可以从letsencrypt获得免费的TLS证书,工作正常,每3个月需要自动刷新一次。

Mozilla的好朋友制作了一个nginx配置生成器

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

您指定哪个版本的nginx,它会为您提供有效的配置文件

答案 1 :(得分:0)

以下是您需要执行的步骤,以便在ubuntu上为nginx Web服务器安装免费的SSL。 步骤1.使用SSH登录到Cloud VPS服务器

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

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

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

更改Godaddy帐户中的DNS A记录 步骤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;

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

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

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

sudo certbot更新--dry-run

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

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