阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 16.04下Nginx配置HTTPS

153次阅读
没有评论

共计 2235 个字符,预计需要花费 6 分钟才能阅读完成。

下面记录下 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) []:www.mike.me ← 输入主机名 
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 服务器的安装配置  http://www.linuxidc.com/Linux/2017-04/142986.htm

CentOS 上安装 Nginx 服务器实现虚拟主机和域名重定向  http://www.linuxidc.com/Linux/2017-04/142642.htm

CentOS 6.8 安装 LNMP 环境(Linux+Nginx+MySQL+PHP)http://www.linuxidc.com/Linux/2017-04/142880.htm

Linux 下安装 PHP 环境并配置 Nginx 支持 php-fpm 模块  http://www.linuxidc.com/Linux/2017-05/144333.htm

Nginx 服务的 SSL 认证和 htpasswd 认证  http://www.linuxidc.com/Linux/2017-04/142478.htm

Linux 中安装配置 Nginx 及参数详解  http://www.linuxidc.com/Linux/2017-05/143853.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

CentOS 7.2 下 Nginx+PHP+MySQL+Memcache 缓存服务器安装配置  http://www.linuxidc.com/Linux/2017-03/142168.htm

CentOS6.9 编译安装 Nginx1.4.7  http://www.linuxidc.com/Linux/2017-06/144473.htm

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

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-06/144806.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2235字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中