https 需要购买域名ssl证书

注意事项:

1.要开启HTTP/2协议支持,需要在nginx 1.10以上版本并且需要openssl库的版本在1.0.2及以上编译。

2.http2.0只支持开启了https的网站。

openssl version 可以查看openssl版本

nginx -v 可以查看nginx版本

mysql -v 可以查看mysql版本

php -v 可以查看php版本

以下命令可以查看linux版本

uname -a;

more /etc/issue;

cat /proc/version;

开始:

这里我的证书是使用阿里云提供的免费证书

1.下载证书

2.安装证书

文件说明:
1. 证书文件1533488566332.pem,包含两段内容,请不要删除任何一段内容。
2. 如果是证书系统创建的CSR,还包含:证书私钥文件1533488566332.key。
( 1 ) 在Nginx的安装目录下创建cert目录,并且将下载的全部文件拷贝到cert目录中。如果申请证书时是自己创建的CSR文件,请将对应的私钥文件放到cert目录下并且命名为1533488566332.key;
( 2 ) 打开 Nginx 安装目录下 conf 目录中的 nginx.conf 文件,找到:
# HTTPS server
# #server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
#
#
#}
#}
( 3 ) 将其修改为 (以下属性中ssl开头的属性与证书配置有直接关系,其它属性请结合自己的实际情况复制或调整) :
server {
listen 443;
server_name localhost;
ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/1533488566332.pem;
ssl_certificate_key cert/1533488566332.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}

保存退出。

( 4 )重启 Nginx。
( 5 ) 通过 https 方式访问您的站点,测试站点证书的安装配置。

问题:但是安装后 执行 systemctl start nginx  报错  the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf

原来是nginx安装时候没有加载 ssl模块 和 http2模块

1)切换到nginx源码包

cd /usr/local/src/nginx-1.11.3
2)查看ngixn原有的模块
/usr/local/nginx/sbin/nginx -V
显示 --prefix=/usr/local/nginx 需要后面加上需要的模块--with-http_stub_status_module --with-http_ssl_module --with-http_v2_module
--with-http_v2_module 是支持http2 的模块 支持http2需要满足 
3)重新配置
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module
4)重新编译,不需要make  install安装。否则会覆盖
make
5)备份原有已经安装好的nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
6)将刚刚编译好的nginx覆盖掉原来的nginx(ngixn必须停止)
cp ./objs/nginx /usr/local/nginx/sbin/ 
这时,会提示是否覆盖,请输入yes,直接回车默认不覆盖
7)启动nginx,查看nginx模块,发现已经添加
/usr/local/nginx/sbin/nginx -V 
最后附上完整的ngixn配置:
user nginx nginx;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048; gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 8;
gzip_vary on;
gzip_types text/plain application/x-javascript text/css text/json application/xml text/javascript application/javascript;
gzip_disable "MSIE"; server_tokens off; # sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
# keepalive_timeout 65; #gzip on; server {
listen 80;
server_name localhost;
root /data;
#charset koi8-r; #access_log logs/host.access.log main; location / {
root /data;
index index.php index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /data;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /data;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} server {
listen 80;
server_name www.fibst.cn;
return 301 https://$server_name$request_uri;
} server{
#listen 80;
listen 443 ssl http2;
server_name www.fibst.cn;
ssl on;
ssl_certificate cert/www.fibst.cn.pem;
ssl_certificate_key cert/www.fibst.cn.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; root /data/suxiaoying/;
index index.html index.htm index.php; location ~ ^(.*)\/\.svn\/ {
return 404;
} location / {
try_files $uri $uri/ /index.php$is_args$args;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
} }

  

给自己网站配置 https,http2 ,gzip压缩的更多相关文章

  1. 网站配置https(腾讯云域名操作)

    我们都知道http协议是超文本传输协议,早期的网站使用的都是http,但是并不安全,数据在传输过程中容易被拦截篡改.所以后面有了https,也就是经过ssl加密的http协议.本文主要对网站配置htt ...

  2. 【转载】网站配置Https证书系列(二):IIS服务器给网站配置Https证书

    针对网站的Https证书,即SSL证书,腾讯云.阿里云都提供了免费的SSL证书申请,SSL证书申请下来后,就需要将SSL证书配置到网站中,如果网站使用的Web服务器是IIS服务器,则需要在IIS服务器 ...

  3. 【转载】网站配置Https证书系列(三):IIS网站设置Http链接直接跳转Https安全连接

    Http链接请求是以明文的方式传输,在传输的过程中很容易被篡改数据,一个典型的例子就是运营商的网络劫持注入广告信息等,而Https请求则是安全加密的请求,报文数据以密文的形式进行传输.当IIS网站配置 ...

  4. iis6配置使用页面Gzip压缩提速

    iis7默认就启用了Gzip压缩,节约带宽,流量,能够很明显的提升访问速度,但是iis6则没有,本文就是介绍如何通过配置开启iis6的Gzip压缩 一. HTTP压缩概述 HTTP压缩是在Web服务器 ...

  5. nginx缓存配置及开启gzip压缩

    阅读目录 一:nginx缓存配置 二:nginx开启gzip 回到顶部 一:nginx缓存配置 在前一篇文章,我们理解过http缓存相关的知识点, 请看这篇文章. 今天我们来学习下使用nginx服务来 ...

  6. 【转载】网站配置Https证书系列(一):腾讯云申请免费的SSL证书的流程步骤(即https安全连接使用的证书)

    很多网站为了安全性考虑都会上https安全连接,此时就需要考虑使用SSL证书,其实在腾讯云这边提供有免费的SSL证书申请,登录腾讯云管理控制台后,进入SSL证书管理页面,里面有个申请免费证书.腾讯云申 ...

  7. CentOS给网站配置Https证书

    1.在腾讯云申请域名的证书 2.配置文件 安装相应模块: yum install mod_ssl openssl 编辑配置文件: cd /etc/httpd/conf.d vi jerryqi.con ...

  8. 服务器网页GZIP压缩怎么配置

    服务器网页GZIP压缩怎么配置     服务器网页GZIP压缩怎么配置,GZIP压缩对网页压缩来说最好不过了,下面是IIS下Gzip配置详细操作步骤:     简单来说,IIS6集成了Gzip,只不过 ...

  9. Tomcat7中开启gzip压缩功能的配置方法

    使用gzip压缩可以减少数据传输大小,加快网页加载速度.很多大站都开启了gzip压缩,不过也有很多网站并没有开启gzip压缩,上次看了一篇文章说开启gzip压缩后对搜索引擎不友好,但从带宽和流量的角度 ...

随机推荐

  1. 【ADO.NET基础-数据加密】第一篇(加密解密篇)

    可以采用下面的函数实现密码的加密 public static string EncryptString(string str) { //密文 string key = "www"; ...

  2. ArchLinux安(重)装指南

    说实话,我其实是不想要出这篇博客的.在我这一个月安装Arch的过程中,让我感触比较深的一点是: 没有谁比这个系统的官方更懂它. 尤其是这种比较复杂的系统,更是如此. 这几天,我经历了一次重装,系统坏了 ...

  3. Java基础学习笔记(三) - 抽象类和接口

    一.抽象类 没有方法主体的方法称为抽象方法,包含抽象方法的类就是抽象类. Java中使用 abstract 关键字修饰方法和类,抽象方法只有一个方法名,没有方法体. public abstract c ...

  4. Creator3D长什么样?看看官方惊艳的DEMO就知道了,附在线体验!

    Shawn 这两天在学习 Creator3D 的官方案例,由于是刚接触 Creator3D 很多东西在没弄清楚之前还是以简单的编辑介绍为主,先了解一下3D场景的基本操作: 观查场景:按住鼠标右键以自己 ...

  5. js常用Matn函数的操练

    Math.PI console.log(Math.PI); 随机数以及向下取整 这是一个能实现从a-b之间随机打印一个整数 function rand_s(a, b) { var x = a + (b ...

  6. 配置中心-Apollo

    配置中心-Apollo 2019/10/01 Chenxin 配置服务主要有 携程Apollo.百度Disconf.阿里ACM,目前以Apollo用户量最大.适用场景,多用于微服务,与K8S结合好. ...

  7. 浅析MVC Pattern

    一.前言 最近做CAD插件相关的工作,用到了一些模式,解决对应场景的问题. 比如插件的运行实例上使用Singleton.实例内部使用了MVC(Strategy and Observer ). 针对CA ...

  8. Mac 下安装配置MongoDB讲解

    1.访问官网地址是:MongoDB Download Center | MongoDB,一般下载server的Community 版,对于一般开发人员来说已经够用了.   2.点击“DOWNLOAD( ...

  9. 【POJ2001】Shortest Prefixes

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18724   Accepted: 810 ...

  10. LeetCode初级算法--数组02:旋转数组

    LeetCode初级算法--数组02:旋转数组 搜索微信公众号:'AI-ming3526'或者'计算机视觉这件小事' 获取更多算法.机器学习干货 csdn:https://blog.csdn.net/ ...