Ubuntu 16.04下Nginx配置HTTPS

下面记录下64位Ubuntu 16.04.1下,Nginx 1.10.1配置HTTPS的方法,Ubuntu下apt-get install nginx 的 Nginx默认是支持SSL的。

1、生成自签名证书:

cd /var/www

mkdir ssl
cd ssl
sudo openssl genrsa -des3 -out server.key 1024 
sudo openssl req -new -key server.key -out server.csr
sudo openssl rsa -in server.key -out server_nopwd.key 
sudo openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt 

其中证书的生成过程大致如下

linuxidc@ubuntu:~$ sudo openssl req -new -key server.key -out server.csr 
Enter pass phrase for server.key:  ←输入第一步中生成server.key时设置的密码 
You are about to be asked to enter information that will be incorporated 
into your certificate request. 
What you are about to enter is what is called a Distinguished Name or a DN. 
There are quite a few fields but you can leave some blank 
For some fields there will be a default value, 
If you enter '.', the field will be left blank. 
----- 
Country Name (2 letter code) [AU]:CN ←输入国家代码 
State or Province Name (full name) [Some-State]:CHONGQING ← 输入省名 
Locality Name (eg, city) []:CHONGQING ←输入城市名 
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MIKE ← 输入公司名 
Organizational Unit Name (eg, section) []:MIKE ← 输入组织单位名 
Common Name (eg, YOUR name) []: ← 输入主机名 
Email Address []:easylife206@gmail.com ←输入电子邮箱地址 
← 回车
← 回车

2、配置Nginx HTTPS访问:

sudo vim /etc/nginx/sites-available/default 
sudo vim /etc/nginx/sites-available/default

server { 
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

###其他配置
 
    ssl                  on; 
    ssl_certificate      /var/www/ssl/server.crt; 
    ssl_certificate_key  /var/www/ssl/server_nopwd.key;
    ###
 } 

OK,然后我们重新加载下nginx配置文件: service nginx restart

CentOS 7下Nginx服务器的安装配置 

CentOS上安装Nginx服务器实现虚拟主机和域名重定向 

CentOS 6.8 安装LNMP环境(Linux+Nginx+MySQL+PHP) 

Linux下安装PHP环境并配置Nginx支持php-fpm模块 

Nginx服务的SSL认证和htpasswd认证 

Linux中安装配置Nginx及参数详解 

Nginx日志过滤 使用ngx_log_if不记录特定日志

CentOS 7.2下Nginx+PHP+MySQL+Memcache缓存服务器安装配置 

CentOS6.9编译安装Nginx1.4.7 

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/cfd39bc305dd9000b2550fa0d5e294cb.html