在ubuntu 上创建 ssl 证书

soap webservice 调试工具: soap UI, 可以下载下来玩一玩。

Introduction

TLS, or transport layer security, and its predecessor SSL, which stands for secure sockets layer, are web protocols used to wrap normal traffic in a protected, encrypted wrapper.

Using this technology, servers can send traffic safely between the server and the client without the concern that the messages will be intercepted and read by an outside party. The certificate system also assists users in verifying the identity of the sites that they are connecting with.

In this guide, we will show you how to set up a self-signed SSL certificate for use with an Nginx web server on an Ubuntu 14.04 server. A self-signed certificate will not validate the identity of your server for your users since it is not signed by one of their web browser‘s trusted certificate authorities, but it will allow you to encrypt communications with your web clients.

Prerequisites

To get started on this guide, you will need to set up some basic things on your server.

You should have a non-root user available who has sudo privileges. You can learn how to set up such a user account by following steps 1-4 in our initial server setup for Ubuntu 14.04.

After that, you‘ll also need to have the Nginx web server installed. If you would like to install an entire LEMP (Linux, Nginx, MySQL, PHP) stack on your server, you can follow our guide on setting up LEMP on Ubuntu 14.04.

If you just want the Nginx web server, you can instead just type:

sudo apt-get update
sudo apt-get install nginx

Step One — Create the SSL Certificate

We can start off by creating a directory that will be used to hold all of our SSL information. We should create this under the Nginx configuration directory:

sudo mkdir /etc/nginx/ssl

Now that we have a location to place our files, we can create the SSL key and certificate files in one motion by typing:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt

You will be asked a series of questions. Before we go over that, let‘s take a look at what is happening in the command we are issuing:

  • openssl: This is the basic command line tool for creating and managing OpenSSL certificates, keys, and other files.
  • req: This subcommand specifies that we want to use X.509 certificate signing request (CSR) management. The "X.509" is a public key infrastructure standard that SSL and TLS adheres to for its key and certificate management. We want to create a new X.509 cert, so we are using this subcommand.
  • -x509: This further modifies the previous subcommand by telling the utility that we want to make a self-signed certificate instead of generating a certificate signing request, as would normally happen.
  • -nodes: This tells OpenSSL to skip the option to secure our certificate with a passphrase. We need Nginx to be able to read the file, without user intervention, when the server starts up. A passphrase would prevent this from happening because we would have to enter it after every restart.
  • -days 365: This option sets the length of time that the certificate will be considered valid. We set it for one year here.
  • -newkey rsa:2048: This specifies that we want to generate a new certificate and a new key at the same time. We did not create the key that is required to sign the certificate in a previous step, so we need to create it along with the certificate. The rsa:2048 portion tells it to make an RSA key that is 2048 bits long.
  • -keyout: This line tells OpenSSL where to place the generated private key file that we are creating.
  • -out: This tells OpenSSL where to place the certificate that we are creating.

As we stated above, these options will create both a key file and a certificate. We will be asked a few questions about our server in order to embed the information correctly in the certificate.

Fill out the prompts appropriately. The most important line is the one that requests the Common Name (e.g. server FQDN or YOUR name). You need to enter the domain name that you want to be associated with your server. You can enter the public IP address instead if you do not have a domain name.

The entirety of the prompts will look something like this:

Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:New York City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Bouncy Castles, Inc.
Organizational Unit Name (eg, section) []:Ministry of Water Slides
Common Name (e.g. server FQDN or YOUR name) []:your_domain.com
Email Address []:[email protected]_domain.com

Both of the files you created will be placed in the /etc/nginx/ssl directory.

Step Two — Configure Nginx to Use SSL

We have created our key and certificate files under the Nginx configuration directory. Now we just need to modify our Nginx configuration to take advantage of these by adjusting our server block files. You can learn more about Nginx server blocks in this article.

Nginx versions 0.7.14 and above (Ubuntu 14.04 ships with version 1.4.6) can enable SSL within the same server block as regular HTTP traffic. This allows us to configure access to the same site in a much more succinct manner.

Your server block may look something like this:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm;

        server_name your_domain.com;

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

The only thing we would need to do to get SSL working on this same server block, while still allowing regular HTTP connections, is add a these lines:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        listen 443 ssl;

        root /usr/share/nginx/html;
        index index.html index.htm;

        server_name your_domain.com;
        ssl_certificate /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;

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

When you are finished, save and close the file.

Now, all you have to do is restart Nginx to use your new settings:

sudo service nginx restart

This should reload your site configuration, now allowing it to respond to both HTTP and HTTPS (SSL) requests.

Step Three — Test your Setup

Your site should now have SSL functionality, but we should test it to make sure.

First, let‘s test to make sure we can still access the site with using normal HTTP. In your web browser, go to your server‘s domain name or IP address:

http://server_domain_or_IP

You should see your normal website. In my example, I‘m just serving the default Nginx page:

If you get this page, then your server is still handling HTTP requests correctly.

Now, we can check whether our server can use SSL to communicate. Do this by specifying the httpsprotocol instead of the http protocol.

https://server_domain_or_IP

You will likely get a warning in your web browser that looks something like this:

This is expected. It is telling you that it cannot verify the identity of the server you are trying to connect to because it isn‘t signed by a certificate authority that the browser has been configured to trust. Since we created a self-signed certificate, this makes perfect sense.

Click on "Proceed anyway", "Continue", or whatever similar option is available. You should see your site again:

Your browser may show the "https" crossed out in the address bar or a broken or crossed out "lock" icon. If you click on the lock icon, you can see some more information about the connection:

As you can see, the issue is only that the browser cannot verify the identity of the server because it isn‘t signed by a certificate authority that it is configured to trust. The middle section shows that the connection is encrypted, however, so we have achieved that goal.

Conclusion

You have configured your Nginx server to handle both HTTP and SSL requests. This will help you communicate with clients securely and avoid outside parties from being able to read your traffic.

If you are planning on using SSL for a public website, you should probably purchase an SSL certificate from a trusted certificate authority to prevent the scary warnings from being shown to each of your visitors.

时间: 2024-10-10 20:34:16

在ubuntu 上创建 ssl 证书的相关文章

在Apache服务器上安装SSL证书

在Apache服务器上安装SSL证书 阿里云SSL证书服务支持下载证书安装到Apache服务器,从而使Apache服务器支持HTTPS安全访问.本文介绍了证书安装的具体操作. 前提条件 您的Apache服务器上已经开启了443端口(HTTPS服务的默认端口). 您的Apache服务器上已安装了mode_ssl.so模块(启用SSL功能). 本文档证书名称以domain name为示例,例如:证书文件名称为domain name_public.crt,证书链文件名称为domain name_cha

菜鸟玩云计算之十五:在Ubuntu上创建和管理Redhat虚拟机

菜鸟玩云计算之十五:在Ubuntu上创建和管理Redhat虚拟机 [email protected] 虚拟机给工作带来巨大的便利,不仅仅体现在资源的按需使用,而且配置的迁移特别方便.本文将使用Ubuntu14.04 Desktop版本创建Redhat 64 Enterprise Server(RHEL64)虚拟机. 1 准备好安装光盘镜像 rhel-server-6.4-x86_64-dvd.iso 2 打开虚拟机管理器 尽管可以用命令行的方式创建虚拟机,但是本着简单事情简单做的原则,我使用vi

阿里云在Nginx/Tengine服务器上安装证书和在IIS服务器上安装SSL证书

在Nginx/Tengine服务器上安装证书 https://help.aliyun.com/document_detail/98728.html?spm=5176.2020520163.0.0.3c3856a7A8zZ8s 在IIS服务器上安装SSL证书 https://help.aliyun.com/document_detail/98729.html?spm=5176.2020520163.0.0.3c3856a7A8zZ8s 原文地址:https://www.cnblogs.com/pa

创建ssl 证书

openssl req -new -newkey rsa:4096 -nodes -sha256  -keyout myserver.key -out server.csr 创建所需的key 和csr 文件 然后按照提示添加相应的内容 Country Name (2?letter code):HK State or Province Name (eg. City):Hong Kong Locality Name (eg. Company):SMARTBUYGLASSES OPTICAL LIMI

服务器上安装SSL证书的好处

服务器上安装了SSL证书之后会不会影响用户浏览网页的速度呢??? 服务器上装SSL证书会增加服务器CPU的处理负担,因为要为每一个SSL连接实现加密和解密,但一般不会影响太大.同时建议您注意以下几点以减轻服务器的负担: ?仅为需要加密的页面使用SSL,如https://www.domain.com/login.asp,不要把所有页面都使用https://, 特别是访问量最大的首页.?尽量不要在使用了SSL的页面上设计大块的图片文件和其他大文件,尽量使用简洁的 文字页面. SSL证书的作用对网站信

为horizon7 Connection server创建SSL证书

环境: Horizon 7.5 Connection Server :windows 2008 R2 AD域控:windows 2012 R2 CA服务器:windows 2012 R2 详细步骤: 1.Connection Server安装 安装完后加入域,详细过程略. 2.CA服务器安装配置 首先将CA服务器加入域环境. 添加角色和功能--勾选"Active Directory证书服务"角色 此处只要默认勾选"证书颁发机构"即可 安装完后,开始进入配置证书服务页

在ubuntu上创建scrapy爬虫

下载scrapy 在命令行下输入: sudo apt-get install python-scrapy 或者进入http://scrapy.org下载安装 新建项目 命令行下进入项目目录,输入scrapy startproject start 新建一个名为start的项目 项目结构如下 start/ scrapy.cfg start/ __init__.py items.py pipelines.py settings.py spiders/ __init__.py 各文件的作用如下: scr

用XCA(X Certificate and key management)可视化程序管理SSL 证书(3)--创建自定义的凭证管理中心(Certificate Authority)

在第"用XCA(X Certificate and key management)可视化程序管理SSL 证书(2)---创建证书请求"章节中,我们介绍了如何用XCA创建SSL证书请求(Certificate Request),在一章节中,同时提到了如何对证书请求,用我们自己的创建的凭证管理中心(Certificate Authority)进行签名:但是在做这一步之前,我们首先需要知道如何创建一个属于咱们自己的凭证管理中心(Certificate Authority). 步骤很简单,具体

阿里云和腾讯云免费SSL证书

概述 什么是SSL证书 通俗的来讲SSL和TSL都是属于网络传输的安全协议,而SSL继承于TSL,且SSL是一种更为安全的加密协议. SSL和TSL的体现: TSL是通过浏览器以http://来访问,默认端口是80: SSL是通过浏览器以https://来访问,默认端口是443. 为什么要使用SSL SSL更加安全 在使用微信小程序开发时与后台数据交互必须使用https传输,即SSL协议 SSL如何获得 SSL证书在很多网站上都有出售,且价格都不便宜(对我来说蛮贵的) 在阿里云和腾讯云上面都有免