How To Create a SSL Certificate on Apache for Ubuntu 14.04

Ubuntu 20.04下Apache自签名SSL证书配置实战 SSL证书是TLS协议中实现服务器身份认证的核心机制,其本质并非加密数据,而是通过数字签名建立可信的身份信封。在开发、测试及内网场景中,自签名证书提供了一种零成本、离线可控的HTTPS启用方案,具备与商业证书同等的加密强度(如RSA-2048或ECDSA),仅缺失第三方CA背书。它广泛应用于Docker微服务通信、Vue/React本地HTTPS开发、Jenkins/GitLab内网管理等场景,有效规避混合内容错误、CI/CD构建失败(如no required ssl certificate was sen 阅读详情

这篇教程简单实用,配置出来默认就是tls1.2了,但是我翻墙不稳定,所以怕以后急用却翻不了墙,所以转载过来了,原文地址:

https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04

Introduction

TLS, or transport layer security, and its predecessor SSL, secure sockets layer, are secure protocols created in order to place normal traffic in a protected, encrypted wrapper.

These protocols allow traffic to be sent safely between remote parties without the possibility of the traffic being intercepted and read by someone in the middle. They are also instrumental in validating the identity of domains and servers throughout the internet by establishing a server as trusted and genuine by a certificate authority.

In this guide, we'll cover how to create a self-signed SSL certificate for Apache on an Ubuntu 14.04 server, which will allow you to encrypt traffic to your server. While this does not provide the benefit of third party validation of your server's identity, it fulfills the requirements of those simply wanting to transfer information securely.

Note: You may want to consider using Let's Encrypt instead of a self-signed certificate. Let's Encrypt is a new certificate authority that issues free SSL/TLS certificates that are trusted in most web browsers. Check out the tutorial to get started: How To Secure Apache with Let's Encrypt on Ubuntu 14.04

Prerequisites

Before you begin, you should have some configuration already taken care of.

We will be operating as a non-root user with sudo privileges in this guide. You can set one up by following steps 1-4 in our Ubuntu 14.04 initial server setup guide.

You are also going to need to have Apache installed. If you don't already have that up and running, you can quickly fix that by typing:

sudo apt-get update
sudo apt-get install apache2

Step One — Activate the SSL Module

SSL support actually comes standard in the Ubuntu 14.04 Apache package. We simply need to enable it to take advantage of SSL on our system.

Enable the module by typing:

sudo a2enmod ssl

After you have enabled SSL, you'll have to restart the web server for the change to be recognized:

sudo service apache2 restart

With that, our web server is now able to handle SSL if we configure it to do so.

Step Two — Create a Self-Signed SSL Certificate

Let's start off by creating a subdirectory within Apache's configuration hierarchy to place the certificate files that we will be making:

sudo mkdir /etc/apache2/ssl

Now that we have a location to place our key and certificate, we can create them both in one step by typing:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
(注:可以指定签名算法,比如sha256,加上参数“-sha256”即可, 但是需要执行一下:openssl list-message-digest-algorithms,看看支不支持。有的用sha1,md5算法,有可能遭受碰撞攻击)

Let's go over exactly what this means.

  • openssl: This is the basic command line tool provided by OpenSSL to create and manage certificates, keys, signing requests, etc.
  • req: This specifies a subcommand for X.509 certificate signing request (CSR) management. X.509 is a public key infrastructure standard that SSL adheres to for its key and certificate managment. Since we are wanting to create a new X.509 certificate, this is what we want.
  • -x509: This option specifies that we want to make a self-signed certificate file instead of generating a certificate request.
  • -nodes: This option tells OpenSSL that we do not wish to secure our key file with a passphrase. Having a password protected key file would get in the way of Apache starting automatically as we would have to enter the password every time the service restarts.
  • -days 365: This specifies that the certificate we are creating will be valid for one year.
  • -newkey rsa:2048: This option will create the certificate request and a new private key at the same time. This is necessary since we didn't create a private key in advance. The rsa:2048 tells OpenSSL to generate an RSA key that is 2048 bits long.
  • -keyout: This parameter names the output file for the private key file that is being created.
  • -out: This option names the output file for the certificate that we are generating.

When you hit "ENTER", you will be asked a number of questions.

The most important item that is requested is the line that reads "Common Name (e.g. server FQDN or YOUR name)". You should enter the domain name you want to associate with the certificate, or the server's public IP address if you do not have a domain name.

The questions portion looks 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]:Your Company
Organizational Unit Name (eg, section) []:Department of Kittens
Common Name (e.g. server FQDN or YOUR name) []:your_domain.com
Email Address []:your_email@domain.com

The key and certificate will be created and placed in your /etc/apache2/ssl directory.

Step Three — Configure Apache to Use SSL

Now that we have our certificate and key available, we can configure Apache to use these files in a virtual host file. You can learn more about how to set up Apache virtual hosts here.

Instead of basing our configuration file off of the 000-default.conf file in the sites-availablesubdirectory, we're going to base this configuration on the default-ssl.conf file that contains some default SSL configuration.

Open the file with root privileges now:

sudo nano /etc/apache2/sites-available/default-ssl.conf

With the comments removed, the file looks something like this:

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>
        BrowserMatch "MSIE [2-6]" \
                        nokeepalive ssl-unclean-shutdown \
                        downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    </VirtualHost>
</IfModule>

This may look a bit complicated, but luckily, we don't need to worry about most of the options here.

We want to set the normal things we'd configure for a virtual host (ServerAdmin, ServerName, ServerAlias, DocumentRoot, etc.) as well as change the location where Apache looks for the SSL certificate and key.

In the end, it will look something like this. The entries in red were modified from the original file:

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin admin@example.com
        ServerName your_domain.com
        ServerAlias www.your_domain.com
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>
        BrowserMatch "MSIE [2-6]" \
                        nokeepalive ssl-unclean-shutdown \
                        downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    </VirtualHost>
</IfModule>

Save and exit the file when you are finished.

Step Four — Activate the SSL Virtual Host

Now that we have configured our SSL-enabled virtual host, we need to enable it.

We can do this by typing:

sudo a2ensite default-ssl.conf

We then need to restart Apache to load our new virtual host file:

sudo service apache2 restart

This should enable your new virtual host, which will serve encrypted content using the SSL certificate you created.

Step Five — Test your Setup

Now that you have everything prepared, you can test your configuration by visiting your server's domain name or public IP address after specifying the https:// protocol, like this:

https://server_domain_name_or_IP

You will get a warning that your browser cannot verify the identity of your server because it has not been signed by one of the certificate authorities that it trusts.

apache ssl warning

This is expected since we have self-signed our certificate. While our certificate will not validate our server for our users because it has had no interaction with a trusted certificate authority, it will still be able to encrypt communication.

Since this is expected, you can hit the "Proceed anyway" button or whatever similar option you have in your browser.

You will now be taken to content in the DocumentRoot that you configured for your SSL virtual host. This time your traffic is encrypted. You can check this by clicking on the lock icon in the menu bar:

apache ssl encrypted

You can see in the middle green section that the connection is encrypted.

Conclusion

You should now have SSL enabled on your website. This will help to secure communication between visitors and your site, but it will warn each user that the browser cannot verify the validity of the certificate.

If you are planning on launching a public site and need SSL, you will be better off purchasing an SSL certificate from a trusted certificate authority.

If you want to learn more about how to configure Apache, click here. Check out this link for more ideas on how to secure your Linux server.

By Justin Ellingwood

Ubuntu 14.04 Apache虚拟主机精准配置指南 Apache虚拟主机是Web服务实现多站点隔离的核心机制,其原理基于HTTP Host头匹配与Listen指令协同的请求路由机制。在Ubuntu等Debian系系统中,它依托sites-available/sites-enabled目录结构、a2ensite工具链及严格的权限模型实现工程化管理。技术价值在于以零额外组件成本达成域名级隔离、独立日志、差异化SSL策略与故障域收敛。典型应用场景包括老旧VPS多租户托管、工控/金融边缘设备Web管理界面部署,以及遗留系统安全加固。本文聚焦Ubuntu 14.04 阅读详情

相关推荐

Ubuntu 14.04 Apache SSL配置实战:自签名证书与OpenSSL 1.0.1f兼容指南

HTTPS 是现代 Web 服务的基础安全机制,其核心依赖于 SSL/TLS 协议栈、X.509 证书体系与 Web 服务器的加密模块协同工作。在老旧但仍在服役的 Linux 环境中,Ubuntu 14.04 搭配 Apache 2.4.7 和 OpenSSL 1.0.1f 构成了一类典型受限系统——它不支持 Let’s Encrypt 自动化工具链,缺乏 TLS 1.3 与现代密码套件,且对证书链加载、私钥权限、SNI 兼容性等细节高度敏感。理解其底层约束(如 `SSLCertificateChainFi

weixin_30291791的博客 370

How to create a ssl certificate on apache2 for Ubuntu 12.04+

转自: https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-12-04 (暂未转载完毕) ----------------------------------------- &以下参考: http://w

shunbenben的专栏 669

Ubuntu Apache自签名SSL证书完整实战指南

SSL证书是HTTPS通信的信任基石,其核心在于X.509标准、公钥基础设施(PKI)及TLS握手机制。自签名证书虽不依赖公共CA,但需严格遵循密钥生成、CSR构造、SubjectAltName(SAN)声明与Apache配置等技术规范,方能支撑本地开发、Docker容器、Kubernetes服务等内网场景的可信加密通信。它直接解决‘x509: cannot validate certificate for IP’和‘certificate signed by unknown authority’等高频报错

weixin_33739627的博客 493

Ubuntu 18.04 上安全部署 Webmin 并集成 Apache 与 Let‘s Encrypt

Webmin 是一款面向 Linux 系统的 Web 化运维管理工具,其核心价值在于将 Shell 命令、服务配置与系统审计能力封装为浏览器可操作界面。它不替代命令行,而是通过 HTTP 接口实现对 systemctl、Apache 配置、iptables 等底层能力的安全可视化调用。在长期服役的 Ubuntu 18.04 环境中,Webmin 因兼容性稳定、侵入性低,成为教育、工控及内网服务器的关键运维杠杆。结合 Let's Encrypt 实现 HTTPS 加密访问,并深度对接系统原生 Apache 2

weixin_34087307的博客 856

Ubuntu 20.04 Apache SSL部署排错指南:Let‘s Encrypt证书配置与加固

SSL/TLS 是现代 Web 服务安全通信的基础协议,其核心在于证书管理、协议协商与服务器配置的协同。Apache 作为主流 Web 服务器,需结合 OpenSSL 实现 TLS 握手,而 Let's Encrypt 提供免费、自动化、符合 ACME 协议的 X.509 证书分发机制。在 Ubuntu 20.04 这一长期支持版本中,因 OpenSSL 1.1.1f 默认策略、Apache 2.4.41 模块加载时序及 Certbot 版本兼容性等问题,SSL 部署极易出现证书未生效、HTTPS 访问失败

a1311010193的博客 393

Ubuntu 18.04 下安全安装与配置 Webmin 管理 Apache 和 SSL 证书

Webmin 是一款面向传统 Linux 服务器的轻量级系统管理工具,其核心原理是通过 Perl 脚本直接读写标准配置文件(如 /etc/apache2/、/etc/ssl/),绕过复杂依赖与容器化抽象,从而在老旧系统中保持高度兼容性。该技术价值在于为缺乏 DevOps 工具链的运维场景提供可审计、可回滚、低侵入的图形化管理能力,尤其适用于 Apache 虚拟主机配置、SSL 证书部署与 Let’s Encrypt 自动化等高频运维任务。典型应用场景包括教育实验室服务器、工业控制设备、嵌入式网关及 ESM

weixin_30312563的博客 414

Ubuntu Apache自签名SSL证书配置:解决IP和域名SAN缺失问题

自签名SSL证书是开发测试环境实现HTTPS的基础技术,其核心原理在于X.509标准中Subject Alternative Name(SAN)字段对服务端身份的显式声明。现代浏览器与curl等工具强制校验SAN,若证书缺失IP地址或域名条目,将触发x509: cannot validate certificate for 192.168.x.x或self signed certificate in certificate chain等错误。该技术价值在于绕过商业CA依赖,支撑本地开发、内网服务及Docke

weixin_34128839的博客 415

Ubuntu 18.04 Apache WebDAV完整部署与排错指南

WebDAV是一种基于HTTP的文件管理协议,广泛应用于企业文档协同、CI/CD归档和远程配置同步等场景。其核心原理是通过PROPFIND、PUT等扩展HTTP方法实现远程文件系统操作,依赖Apache模块链(mod_ssl → mod_authn_core → mod_dav_fs)完成请求解析、认证授权与磁盘映射。技术价值在于零客户端依赖、Windows原生挂载支持及强审计能力,适用于政企内网、工业网关等对稳定性要求极高的生产环境。常见故障如‘no required ssl certificate wa

weixin_34161029的博客 679

Ubuntu 16.04 Apache虚拟主机配置原理与实战

Apache虚拟主机是Linux Web服务实现多站点托管的核心机制,其本质是基于HTTP Host头的请求路由与资源隔离技术。在Ubuntu 16.04这一经典LTS系统中,Apache 2.4.18采用Debian定制化配置体系,通过sites-available/sites-enabled目录分离与a2ensite工具链实现安全、可审计的站点管理。该机制支撑域名级隔离、独立日志、差异化SSL配置及多PHP版本共存等关键能力,广泛应用于VPS托管、教育实验环境和遗留系统运维。理解其Name-based路

com_xpp的专栏 411

Ubuntu 16.04下Webmin安装与SSL/Let‘s Encrypt一体化配置指南

Webmin是一种面向Linux系统的轻量级Web化系统管理工具,其核心原理是通过可视化界面封装底层命令(如systemctl、a2enmod、certbot等),将高风险的手动配置转化为安全可确认的操作流程。该工具的技术价值在于降低运维认知负荷、规避语法错误、沉淀专家经验,特别适用于老旧稳定环境——如已结束官方支持但仍在运行的Ubuntu 16.04系统。在实际应用中,它广泛支撑Apache服务器管理、HTTPS加密部署及Let’s Encrypt证书自动化申请等关键任务,成为教育实验室、嵌入式网关和遗留

ciqiaofu0192的博客 352

Ansible自动化部署Apache:Ubuntu 18.04开箱即用实践

Apache是Linux环境下最主流的Web服务器软件,其配置管理涉及包安装、模块启用、虚拟主机设置、SSL集成与安全加固等多个技术层面。Ansible作为声明式基础设施即代码(IaC)工具,凭借幂等性、可审计性与跨节点一致性,成为标准化部署Apache的理想选择。尤其在长期支持(LTS)系统如Ubuntu 18.04上,其固定的Apache 2.4.29版本、Debian风格配置路径及Python 2.7运行时环境,对自动化工具的兼容性与精准控制提出明确要求。本文围绕Ansible Playbook设计原

weixin_33997389的博客 363

Nginx反向代理Apache共存架构实战(Ubuntu 16.04)

Web服务器反向代理是实现服务协同与安全隔离的核心技术,其本质是通过分层解耦将网络层处理(如SSL终止、HTTP/2、静态分发)与应用层执行(如PHP解析、.htaccess重写)交由不同引擎专精承担。该方案在兼容遗留系统、降低迁移成本、提升并发性能和强化攻击面收敛等方面具有显著工程价值,广泛应用于混合技术栈、老旧基础设施升级及WAF前置等生产场景。本文聚焦Nginx与Apache在同一Ubuntu 16.04系统下的安全共存实践,详解端口绑定、权限隔离、Header透传与.htaccess等效转换等关键落

weixin_33859844的博客 718

Ubuntu 16.04 Apache 配置 Let‘s Encrypt HTTPS 实战指南

HTTPS 是现代 Web 服务的基础安全要求,其核心是通过 TLS 协议实现传输层加密与服务器身份认证;Let’s Encrypt 作为免费、自动化、开放的证书颁发机构(CA),依托 ACME 协议实现证书申请、验证与续期的全生命周期管理;它显著降低 HTTPS 部署门槛,已成为中小团队保障数据机密性、满足浏览器信任策略、通过小程序平台审核及提升 SEO 排名的关键技术路径;典型应用场景包括老旧生产环境(如 Ubuntu 16.04 + Apache 2.4)的安全加固、企业官网与后台系统合规上线、以及

weixin_34121282的博客 497

Ubuntu 14.04下BitTorrent Sync部署与nginx反向代理实战

BitTorrent Sync(后称Resilio Sync)是一种基于P2P架构的去中心化文件同步工具,其核心依赖LTD协议与DHT网络实现设备直连和端到端加密。它不依赖云存储,所有数据流转均在本地节点间完成,天然具备隐私性与带宽高效性。技术价值体现在跨平台一致性、离线可用性及对老旧系统(如Ubuntu 14.04)的长期兼容支持。典型应用场景包括科研数据多机同步、内网代码协作、边缘设备离线备份等。本文聚焦于该工具在Linux发行版Ubuntu 14.04这一经典但受限环境下的完整落地——涵盖.deb包适

weixin_30655569的博客 431

Ubuntu 16.04下Nginx反向代理Apache实战配置指南

Web服务器架构中,反向代理是一种将客户端请求转发至后端服务的关键技术,其核心原理在于分层解耦与职责分离:前端代理处理连接管理、SSL终止、静态资源缓存等I/O密集型任务,后端应用服务器专注业务逻辑执行。该模式显著提升HTTPS性能、增强并发承载能力,并保障老旧系统平滑演进。在Linux服务器环境中,Ubuntu 16.04凭借长期支持特性与成熟软件源,成为部署Nginx+Apache反向代理架构的典型平台;而reverse proxy配置的可靠性,直接取决于端口隔离、头信息透传(如X-Forwarded-

weixin_33965305的博客 393

Ubuntu 14.04 LAMP部署实战:Apache+PHP5+MySQL5.5全链路配置

LAMP(Linux-Apache-MySQL-PHP)作为Web服务的基础运行时环境,其核心价值在于稳定、透明与深度可控。在边缘系统、教育SaaS、工控终端等长生命周期场景中,Ubuntu 14.04仍广泛承载关键业务,而其绑定的Apache 2.4.7、PHP 5.5.9与MySQL 5.5.62构成一套高度耦合的‘时间胶囊’技术栈。理解MPM预分叉模式对PHP模块加载的约束、InnoDB表碎片率的精准诊断逻辑、以及php mysql 某个表有碎片时的低风险修复路径,是保障老旧系统持续可用的技术底线。本

weixin_34367257的博客 312

Ubuntu 14.04 部署 OctoberCMS 2.1 实战指南

PHP 内容管理系统(CMS)是构建动态网站的核心技术栈,其部署稳定性高度依赖底层运行环境。当面对老旧但仍在服役的 Ubuntu 14.04 系统时,开发者需直面 PHP 5.5.9 兼容性、Apache 2.4.7 模块加载、MySQL 5.5 字符集限制及 Composer 1.x 版本锁定等现实约束。OctoberCMS 作为轻量级 Laravel 衍生 CMS,凭借 Twig 模板与模块化架构,在低版本 PHP 环境中仍具工程可行性;而 Ubuntu 14.04 的长期实际使用场景(如政务内网、高校

weixin_33698823的博客 422

Nagios 4.4.6在Ubuntu 14.04上的源码部署与Apache深度集成

Nagios作为经典的开源监控系统,其核心价值在于对基础设施的细粒度掌控与全链路可审计能力。它基于事件驱动架构,通过插件化设计实现服务状态采集,并依赖Apache等Web服务器提供CGI网关、静态资源服务与基础认证。在遗留系统运维、等保合规加固及离线高安全场景中,Nagios 4.x仍具不可替代性——尤其当需规避云依赖、保障日志颗粒度与配置自主权时。本文聚焦Ubuntu 14.04这一典型LTS环境,详解Nagios 4.4.6源码编译、Apache 2.4兼容配置、PHP gettext扩展支持及nagi

weixin_30369041的博客 579
上一篇: 记PHP第几周和日期转换的坑
下一篇: python使用select监听非阻塞socket遇到的问题
ECHOutopia
博客等级 码龄14年 11粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值