操作系统:centos7.2 x64
tengine:Tengine/2.2.0
主机IP: 10.0.0.12

一、安装tengine

1.1 下载源码安装包

1.1.1 源码包pcre-8.40
            用于支持正则表达式

  1. [root@tengine ~]# cd /usr/local/src/
  2. [root@tengine src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

1.1.2 源码包zlib-1.2.11
            用于支持数据压缩

  1. [root@tengine src]# wget http://zlib.net/zlib-1.2.11.tar.gz

1.1.3 源码包openssl-1.0.2
            用于数据加密及支持SSL协议

  1. [root@tengine src]# wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz

1.1.4 源码包jemalloc-4.4.0
            用于优化内存管理

  1. [root@tengine src]# wget https://github.com/jemalloc/jemalloc/archive/4.4.0.tar.gz

1.1.5 源码包tengine-2.2.0

  1. [root@tengine src]# wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
  2. [root@tengine src]# ls
  3. jemalloc-4.4..tar.gz openssl-1.0.2k.tar.gz pcre-8.40.tar.gz tengine-2.2..tar.gz zlib-1.2..tar.gz

1.2 编译安装依赖包

1.2.1 更新工具包

  1. [root@tengine src]# yum install openssl-devel zlib-devel -y

1.2.2 编译pcre

  1. [root@tengine src]# tar xf pcre-8.40.tar.gz
  2. [root@tengine src]# cd pcre-8.40
  3. [root@tengine pcre-8.40]# ./configure --prefix=/usr/local/pcre
  4. [root@tengine pcre-8.40]# make && make install

1.2.3 编译openssl

  1. [root@tengine src]# tar xf openssl-1.0.2k.tar.gz
  2. [root@tengine src]# cd openssl-1.0.2k
  3. [root@tengine openssl-1.0.2k]# ./config --prefix=/usr/local/openssl
  4. [root@tengine openssl-1.0.2k]# make && make install

1.2.4 编译zlib

  1. [root@tengine src]# tar xf zlib-1.2..tar.gz
  2. [root@tengine src]# cd zlib-1.2.
  3. [root@tengine zlib-1.2.]# ./configure --prefix=/usr/local/zlib
  4. [root@tengine zlib-1.2.]# make && make install

1.2.5 编译jemalloc

  1. [root@tengine src]# tar xf jemalloc-4.4..tar.gz
  2. [root@tengine src]# cd jemalloc-4.4.
  3. [root@tengine jemalloc-4.4.]# ./autogen.sh
  4. autoconf
  5. ./autogen.sh: line : autoconf: command not found
  6. Error in autoconf
  7.  
  8. # 安装autoconf包
  9. [root@tengine jemalloc-4.4.]# yum install autoconf -y
  10. [root@tengine jemalloc-4.4.]# ./autogen.sh
  11. [root@tengine jemalloc-4.4.]# make
  12. [root@tengine jemalloc-4.4.]# make install
  13. /usr/bin/install: cannot stat doc/jemalloc.html’: No such file or directory
  14. make: *** [install_doc_html] Error
  15. # 这里只是说明文档和html页面没有,可以忽悠这个错误,可以直接touch
  16. [root@tengine jemalloc-4.4.]# touch doc/jemalloc.html
  17. [root@tengine jemalloc-4.4.]# make install
  18. [root@tengine jemalloc-4.4.]# touch doc/jemalloc.
  19. [root@tengine jemalloc-4.4.]# make install

1.2.8 加载库文件

  1. [root@tengine tengine-2.2.]# echo '/usr/local/pcre/lib/' > /etc/ld.so.conf.d/pcre.conf
  2. [root@tengine tengine-2.2.]# echo '/usr/local/zlib/lib/' > /etc/ld.so.conf.d/zlib.conf
  3. [root@tengine tengine-2.2.]# echo '/usr/local/openssl/lib/' > /etc/ld.so.conf.d/openssl.conf
  4. [root@tengine tengine-2.2.]# echo '/usr/local/lib/' > /etc/ld.so.conf.d/local.conf
  5. [root@tengine tengine-2.2.]# ldconfig -v | less
  6. /usr/local/lib:
  7. libjemalloc.so. -> libjemalloc.so.
  8. /usr/local/openssl/lib:
  9. /usr/local/pcre/lib:
  10. libpcrecpp.so. -> libpcrecpp.so.0.0.
  11. libpcreposix.so. -> libpcreposix.so.0.0.
  12. libpcre.so. -> libpcre.so.1.2.
  13. /usr/local/zlib/lib:
  14. libz.so. -> libz.so.1.2.
  15. ......
  16. ......

1.2.7 编译tengine

  1. [root@tengine src]# tar xf tengine-2.2..tar.gz
  2. [root@tengine src]# cd tengine-2.2.
  3. # 创建tengine运行用户
  4. [root@tengine tengine-2.2.]# groupadd -g www
  5. [root@tengine tengine-2.2.]# useradd -u -g -s /sbin/nologin -M www
  6. # 注意,在编译tengine时候,pcre, openssl, zlib必须指向源码目录,而jemalloc不能指向源码目录。切记!
  7. [root@tengine tengine-2.2.]# ./configure --prefix=/usr/local/tengine --user=www --group=www \
  8. --with-http_stub_status_module \
  9. --with-http_ssl_module \
  10. --with-http_gzip_static_module \
  11. --with-openssl=/usr/local/src/openssl-1.0.2k \
  12. --with-pcre=/usr/local/src/pcre-8.40 \
  13. --with-zlib=/usr/local/src/zlib-1.2. \
  14. --with-jemalloc
  15.  
  16. [root@tengine tengine-2.2.]# make
  17. [root@tengine tengine-2.2.]# make install
  18.  
  19. [root@tengine tengine-2.2.]# cd /usr/local/tengine/
  20. [root@tengine tengine]# ls
  21. conf html include logs modules sbin
  22. [root@tengine tengine]# echo 'PATH=$PATH:/usr/local/tengine/sbin/' > /etc/profile.d/tengine.sh
  23. [root@tengine tengine]# cat !$
  24. cat /etc/profile.d/tengine.sh
  25. PATH=$PATH:/usr/local/tengine/sbin/
  26. [root@tengine tengine]# source /etc/profile.d/tengine.sh
  27. [root@tengine tengine]# nginx
  28. [root@tengine tengine]# netstat -ntplu | grep nginx
  29. tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx: master
  30.  
  31. # tengine编译成功!
  32.  
  33. # 验证jemalloc是否生效
  34. [root@tengine tengine]# yum install lsof -y
  35. [root@tengine tengine]# lsof -n | grep jemalloc
  36. nginx root mem REG , /usr/local/lib/libjemalloc.so.
  37. nginx www mem REG , /usr/local/lib/libjemalloc.so.
  38. # jemalloc 已生效!

1.3 编写服务,实现开机启动

  1. [root@tengine tengine-2.2.]# vim /usr/lib/systemd/system/tengine.service
  2.  
  3. [Unit]
  4. Description=The nginx HTTP and reverse proxy server
  5. After=syslog.target network.target remote-fs.target nss-lookup.target
  6.  
  7. [Service]
  8. Type=forking
  9. PIDFile=/usr/local/tengine/logs/nginx.pid
  10. ExecStartPre=/usr/local/tengine/sbin/nginx -t
  11. ExecStart=/usr/local/tengine/sbin/nginx
  12. ExecReload=/bin/kill -s HUP $MAINPID
  13. ExecStop=/bin/kill -s QUIT $MAINPID
  14. PrivateTmp=true
  15.  
  16. [Install]
  17. WantedBy=multi-user.target
  18.  
  19. [root@tengine tengine-2.2.]# nginx -s stop
  20. [root@tengine tengine-2.2.]# systemctl status tengine
  21. tengine.service - The nginx HTTP and reverse proxy server
  22. Loaded: loaded (/usr/lib/systemd/system/tengine.service; disabled; vendor preset: disabled)
  23. Active: inactive (dead)
  24.  
  25. # 启动服务
  26. [root@tengine tengine-2.2.]# systemctl start tengine
  27. [root@tengine tengine-2.2.]# netstat -ntplu | grep nginx
  28. tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx: master
  29.  
  30. # 设置开机启动
  31. [root@tengine tengine-2.2.]# systemctl enable tengine
  32. Created symlink from /etc/systemd/system/multi-user.target.wants/tengine.service to /usr/lib/systemd/system/tengine.service.

二、tengine配置SSL并强制使用HTTPS访问

2.1 使用openssl 生成 SSL key 和 CSR

  1. [root@tengine ~]# mkdir /etc/ssl/private
  2. [root@tengine ~]# cd /etc/ssl/private/
  3. [root@tengine private]# openssl req -new -newkey rsa: -sha256 -nodes -out super_com.csr -keyout super_com.key -subj "/C=CN/ST=Beijing/L=Beijing/O=Super Inc./OU=Web Security/CN=super.com"
  4.  
  5. # 这里为了实验,我们自行签发不受浏览器信任的SSL证书
  6.  
  7. [root@tengine private]# openssl x509 -req -days -in super_com.csr -signkey super_com.key -out super_com.crt
  8. Signature ok
  9. subject=/C=CN/ST=Beijing/L=Beijing/O=Super Inc./OU=Web Security/CN=super.com
  10. Getting Private key

2.2 为tengine配置SSL协议认证
        这里配置建议使用以下两种方式:            
            (1)通过tengine write配置正则跳转的方式,该方式会占用服务器资源;
            (2)通过html meta 跳转的方式,百度采用这种方式;
        2.2.1 tengine write方式实现:

  1. [root@tengine ~]# cd /usr/local/tengine/conf/
  2. [root@tengine conf]# vim nginx.conf
  3. ...
  4. ...
  5. http {
  6. server {
  7. listen ;
  8. server_name www.super.com;
  9. rewrite ^(.*)$ https://$host$1 permanent; # 访问的所有url都跳转为https协议
  10. ...
  11. ...
  12. }
  13. include vhost/.conf;
  14. }
  15. ...
  16. ...
  17. [root@tengine conf]# mkdir /usr/local/tengine/conf/vhost
  18. [root@tengine conf]# cd /usr/local/tengine/conf/vhost
           [root@tengine conf]# cp -a /etc/ssl/super_com.crt /etc/ssl/private/
         [root@tengine conf]# cp -a /etc/ssl/super_com.key /etc/ssl/private/
  19. [root@tengine vhost]# vim ssl.conf
  20.  
  21. server {
  22. listen ssl;
  23. ssl on;
  24. ssl_certificate /etc/ssl/private/super_com.crt;
  25. ssl_certificate_key /etc/ssl/private/super_com.key;
  26. location / {
  27. root /usr/local/tengine/html/ssl;
  28. index index.html;
  29. }
  30. }
  31. # 创建网站根目录和测试页面
  32. [root@tengine vhost]# mkdir /usr/local/tengine/html/ssl
  33. [root@tengine vhost]# cd !$
  34. cd /usr/local/tengine/html/ssl
  35. [root@tengine ssl]# echo 'hello 10.0.0.12' > index.html
  36.  
  37. [root@tengine conf]# echo '10.0.0.12 www.super.com' >> /etc/hosts
  38. [root@tengine conf]# ping www.super.com
  39. PING www.super.com (10.0.0.12) () bytes of data.
  40. bytes from www.super.com (10.0.0.12): icmp_seq= ttl= time=0.057 ms
  41. # 重新加载tengine
  42. [root@tengine conf]# nginx -t
  43. nginx: the configuration file /usr/local/tengine/conf/nginx.conf syntax is ok
  44. nginx: configuration file /usr/local/tengine/conf/nginx.conf test is successful
  45. [root@tengine conf]# nginx -s stop # 这里reload不生效可以尝试关闭,在开启
  46. [root@tengine conf]# nginx
  47. [root@tengine conf]# netstat -ntplu | grep nginx
  48. tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx: master
  49. tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx: master
  50. [root@tengine conf]# setenforce ; systemctl stop firewalld # 关闭selinux和防火墙

# 编辑本地主机hosts文件。C:\Windows\System32\drivers\etc\hosts
            10.0.0.12             www.super.com

浏览器访问:http://www.super.com/
           

2.2.2 通过html meta 跳转的方式实现:

  1. [root@tengine conf]# vim nginx.conf
  2. # 将rewrite注释
  3. #rewrite ^(.*)$ https://$host$1 permanent;
  4. [root@tengine conf]# cd /usr/local/tengine/html/
  5. [root@tengine html]# vim index.html
  6.  
  7. <html>
  8. <meta http-equiv="refresh" content="0;url=https://www.super.com/">
  9. </html>

centos7安装tengine强制使用HTTPS访问的更多相关文章

  1. nginx强制使用https访问(http跳转到https)

    Nginx 的 Location 从零开始配置 - 市民 - SegmentFault 思否https://segmentfault.com/a/1190000009651161 nginx配置loc ...

  2. nginx 设置自签名证书以及设置网址http强制转https访问

    自签名证书可以在自己的内网环境或者非对外环境使用,保证通信安装 1.生产证书 直接使用脚本生产: 中途会提示书如1次域名和4次密码,把一下文件保存为sh文件,赋予x权限后 直接执行,根据提示输入. # ...

  3. 解决CentOS7安装Tomcat不能被外部访问的问题

    在CentOS7安装了Tomcat,在服务器内部使用火狐浏览器通过localhost:8080是可以访问的,但是不能被外部访问,主要原因是因为防火墙的存在,导致端口不能被访问.CentOS是使用fir ...

  4. docker下安装nginx并实现https访问

    一.启动容器 docker run --detach --name wx-nginx -p 443:443 -p 80:80 -v /home/nginx/data:/usr/share/nginx/ ...

  5. 安装配置ingress-nginx支持https访问

    说明: ​ 1.k8s版本:v1.23: ​ 2.内网测试环境1台master,2台node节点,使用 DaemonSet+HostNetwork+nodeSelector 方式部署 ingress- ...

  6. centos7安装gitlab 支持带认证https,开启邮件功能 超级简单.

    官方安装说明:https://about.gitlab.com/install/#centos-7 自定义yum源 自行搞定 下载gitlab 官方安装: curl -s https://packag ...

  7. Centos7安装Apache Http服务器无法访问如何解决

    1. 安装Apache组件 [root@mycentos shell]# yum install httpd 2. 安装成功后,检测有无httpd进程 [root@mycentos shell]# p ...

  8. nginx强制使用https访问(多站点多域名配置)

    很多配置过https模板的人都知道,配置https 时 ,站在用户的角度http 和https 的区别根本不清楚.有时候敲 http 时会出现 404 错误,而实际上我们是https. 有朋友找我配置 ...

  9. iOS 9/10强制使用https访问网络,使用了第三方SDK的应用需要配置的信息

    2017年01月01日起苹果将全面禁止使用http来访问网络. 网上扒了一些资源,解决方法还是有的,但是都不确定是否可以通过审核,毕竟实践才是检验真理的唯一标准. 后续如果上线成功,再来分享. 如果应 ...

随机推荐

  1. 容器基础(七): 使用docker compose部署程序

    配置 在上一节的基础上,  增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...

  2. windowsserver2008 重新启动计算机命令

    在windowsserver2008中,若要重新启动计算机,可以输入以下命令即可立即重启计算机shutdown -r -t 0命令意义:shutdown在英文中意为关掉,在计算机中即为关机参数意义:- ...

  3. docker基础-虚拟化与容器介绍

    正如所有关心docker技术的人所知道的那样,docker是以容器虚拟化为技术为基础的软件,因此在学习docker具体的内容之前,有必要讨论一下虚拟化和容器技术. 虚拟化技术: 在了解虚拟化技术时,各 ...

  4. PokeCats开发者日志(三)

      现在是PokeCats游戏开发的第四天的晚上,明天要过周末了,所以提前写一下开发者日志吧! day4   day4主要是优化界面和增加游戏可玩性.   (1)感觉只有三只喵喵的话,玩家只需要无脑点 ...

  5. clone项目到本地

    clone项目到本地 1.然后在本地建立接受代码的文件夹,然后cd 到这个目录 (克隆版本库的时候,所使用的远程主机自动被git命名为origin.如果想用其他的主机名,需要用git clone命令的 ...

  6. php serialize讲解与json性能测试

    [序列化的概念] 序列化是将对象状态转换为可保持或可传输的格式的过程.与序列化相对的是反序列化,它将流转换为对象.这两个过程结合起来,可以轻松地存储和传输数据. 将对象的状态信息转换为可以存储或传输的 ...

  7. [COGS 622] [NOIP2011] 玛雅游戏 模拟

    整个模拟的关键除了打出来就是一个剪枝:对于两个左右相邻的块你不用再走←,因为走→是等效的 #include<cstdio> #include<cstring> #include ...

  8. 如何用setInterval调用类的方法

    setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式.setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭.由 se ...

  9. POJ3189:Steady Cow Assignment(二分+二分图多重匹配)

    Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7482   Accepted: ...

  10. 转:Linux 目录结构和常用命令

    转自:http://www.cnblogs.com/JCSU/articles/2770249.html仅为学习参考之用 一.Linux目录结构 你想知道为什么某些程序位于/bin下,或者/sbin, ...