安装环境:

[root@web01 ~]# uname -r
2.6.32-696.el6.x86_64
[root@web01 ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)

模拟环境需要的硬件:

两台虚拟机:web01(客户端)、lb01(服务端,nginx负载均衡)

安装epel源:
[root@web01 ~]# yum install epel-release.noarch -y
[root@web01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

[root@web01 ~]# yum install bash-completion -y

CentOS6安装Tab增强版:bash-completion,可补全命令参数;

因为CentOS官方源并不带有bash-completion的包,所以,为了可用yum安装,增加epel的源

web01(客户端)

yum安装nginx

[root@web01 ~]#yum install nginx  -y

[root@web01 ~]# nginx -v

nginx version: nginx/1.10.2

yum安装nginx的配置文件位置

[root@web01 ~]#  find / -type f -name "nginx.conf"   ####nginx配置文件

/etc/nginx/nginx.conf

nginx.conf配置文件内容:

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name www.qstar.cn;
        root   html;
        index  index.php index.html index.htm;
        location / {
        }
        location ~ \.php$ {             ######使nginx支持php
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

}

nginx的站点目录下文件:

[root@web01 html]# pwd

/usr/share/nginx/html

[root@web01 html]#  ls

404.html  50x.html  index.html  nginx-logo.png  poweredby.png    ###这里放网站的源代码

启动nginx服务:

[root@web01 ~]#  /etc/init.d/nginx start

Starting nginx:                                            [  OK  ]

查看端口:

[root@web01 ~]#  netstat -lntup

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      4767/nginx

yum安装php,mysql(数据库)

[root@web01 ~]# yum install php-fpm php-cli -y    ####指定php安装最小的模块
[root@web01 ~]# yum install mysql-server  -y    #####mysql-server为服务端,安装时会自动安装mysql客户端

[root@web01 ~]#vim /etc/php-fpm.d/www.conf   #######php-fpm默认配置文件的用户和用户组为apache,修改为nginx

[root@web01 ~]# /etc/init.d/php-fpm start

Starting php-fpm:                                          [  OK  ]

[root@web01 ~]#  /etc/init.d/mysqld start            #######最开始的时候会进行数据库的初始化

Starting mysqld:                                           [  OK  ]

[root@web01 ~]# mysql

mysql> create database cms;    #####创建数据库

mysql> grant all on cms.* to cms@'localhost' identified by '123456';     #####给数据库授予权限

lb01

yum安装nginx

[root@lb01 ~]# yum install nginx  -y

[root@lb01 ~]# nginx -V

nginx version: nginx/1.10.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ld-opt=' -Wl,-E'    #####yum安装nginx自带的编译参数模块

nginx.conf配置文件内容:

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    root   html;
    index  index.php index.html index.htm;
     upstream backend01 {       #######负载均衡的地址池
        server 10.0.0.7  weight=1;     
    }
     server {                   ######将80 端口重定向443端口,让用户可以直接访问www.qstar.cn
        listen       80;     
        server_name   www.qstar.cn; 
        rewrite ^/(.*) https://www.qstar.cn/$1 permanent;  #####rewrite规则
}
    
     server {          #######采用第三方认证的安全证书,颁发证书的平台上会有指导文档
        listen 443;
        server_name www.qstar.cn;
        ssl on;
        ssl_certificate /service/ca/1_www.qstar.cn_bundle.crt;   ####证书文件的所在路径
        ssl_certificate_key /service/ca/2_www.qstar.cn.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

ssl_prefer_server_ciphers on;

location / {
        proxy_pass http://backend01;
        proxy_set_header    Host $host;
        }
    }

}

启动nginx

[root@lb01 ~]# /etc/init.d/nginx restart
Starting nginx:                                            [  OK  ]

Nginx内容替换sub_filter模块的过滤功能

location / {sub_filter      </head>   '</head><script language="javascript" src="x.js"></script>';root   html;index  index.php index.html index.htm;
}

网页访问www.qstar.cn即可!

nginx+php https 实践相关推荐

  1. 大型网站的HTTPS实践:基于协议和配置的优化

    作者 | 百度HTTPS技术支持团队 百度已经上线了全站 HTTPS 的安全搜索,默认会将 HTTP 请求跳转成 HTTPS.百度 HTTPS性能优化涉及到大量内容,在前端页面.后端架构.协议特性.加 ...

  2. Nginx 日志配置实践

    前言 Nginx日志对于统计.系统服务排错很有用. Nginx日志主要分为两种:access_log(访问日志)和error_log(错误日志).通过访问日志我们可以得到用户的IP地址.浏览器的信息, ...

  3. 百度:大型网站的 HTTPS 实践(上)

    百度:大型网站的 HTTPS 实践(上) 来源:百度运维 第一部分:HTTPS 协议和原理 百度已经于近日上线了全站 HTTPS 的安全搜索,默认会将 HTTP 请求跳转成 HTTPS.本文第一部分将 ...

  4. linux6系统下用nginx配置https

    1.cd /usr/local/src 下载解压 wget http://nginx.org/download/nginx-1.14.0.tar.gz ./configure --prefix=/us ...

  5. Nginx配置https,反向代理多实例tomcat的操作记录

    案例说明: 前面一层nginx+Keepalived部署的LB,后端两台web服务器部署了多实例的tomcat,通过https方式部署nginx反向代理tomcat请求.配置一如下: 1)LB层的ng ...

  6. Nginx之https配置

    14.1. 对称加密 安全隐患:钥匙除我之外,还有多个人拥有.泄露风险较大,钥匙传递的过程风险较大 14.2. 非对称加密 优缺点:私钥很安全.但是非对称算法开销很大,大批量应用于业务,会导致性能成本 ...

  7. nginx 配置https 并解决重定向后https协议变成了http的问题

    nginx 配置https 并解决重定向后https协议变成了http的问题 参考文章: (1)nginx 配置https 并解决重定向后https协议变成了http的问题 (2)https://ww ...

  8. nginx 代理https后,应用redirect https变成http --转

    原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明 nginx配置https,tomcat正常http接受nginx转发. n ...

  9. 神奇的nginx之https支持

    引言 随着技术的方法,http传输协议并不能保证数据传输的安全性,随后https技术应运而生,nginx服务器支持https协议,配置的代码也比较难记,记录下以防遗忘. HTTPS数据传输过程 客户端 ...

最新文章

  1. 用C#实现的条形码和二维码编码解码器
  2. 数据分析需求转型与商业模式重构
  3. python什么时候进入中国-python什么时候发明的
  4. 浏览器渲染机制面试_浏览器渲染原理
  5. tf.keras.layers.Permute
  6. 【sql那些事】时间处理的一揽子事
  7. 婚宴座位图html5,婚礼小知识,婚宴座位怎么安排才不得罪人(主桌)
  8. PhoneGap在Microsoft Visual Studio Express For Wi...
  9. 小程序marker 气泡怎么用_小程序直播怎么用,看这里!
  10. 基于Unity引擎的RPG3D项目开发笔录
  11. 自动编号转化为文本_将您的自动回复器转化为潜在客户
  12. 京东个人注册开店要怎么做?京东开店步骤介绍!
  13. 十六、DPM模型-颗粒流动
  14. 苹果软件更新在哪里_苹果iOS 14.1/iPadOS 14.1正式版发布:新增更新机型[多图]-软件资讯...
  15. php thinkadmin自定义一个弹出弹窗批量操作功能
  16. 有没有可以一直做的赚钱副业?
  17. cgb2007-京淘day16
  18. Flutter-防京东商城项目-创建商品数据模型 、请求Api接口渲染热门商品 推荐商品 获取数据然后模型赋值-06
  19. .cfg\.dat\.mak(持续补充)
  20. ajax 异步刷新表格

热门文章

  1. php计算机毕业设计基于thinkph框架的学生宿舍公寓管理系统
  2. WebSecurity
  3. linux之常用指令的英文全称 、中文解释
  4. linux官方桌面大图,Ubuntu 19.04官方壁纸揭晓
  5. PetaLinux 2022.1离线编译配置(sstate和downloads)
  6. 通达信数据excel接口能导出板块数据吗?
  7. [绍棠] Vue六种传值方式
  8. arthas启动-attach流程
  9. BAOCMS怎么样修改默认后台路径admin/login/index.html
  10. 什么是 msvcp120.dll 错误消息?