centos7 安装nginx

nginx安装

  • 前言html

    nginx是一个开源的,支持高性能,高并发的www服务和代理服务软件。它是一个俄罗斯人lgor sysoev开发的,做者将源代码开源出来供全球使用。
    nginx比它大哥apache性能改进许多,nginx占用的系统资源更少,支持更高的并发链接,有更高的访问效率。
    nginx不可是一个优秀的web服务软件,还能够做为反向代理,负载均衡,以及缓存服务使用。
    安装更为简单,方便,灵活。
    nginx能够说是很是nb了
  • Tenginepython

    Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了不少高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等获得了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。nginx

    参考博客:http://tengine.taobao.org/opensource_cn.htmlweb

使用编译安装nginx

  1. 安装前须要安装相关配置软件算法

    OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、经常使用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
    nginx 不只支持 http 协议,还支持 https(即在ssl协议上传输http),因此须要在 Centos 安装 OpenSSL 库。sql

    yum install gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl openssl-devel -y
  2. 下载源码包,注意版本号,可先在官网查看apache

    wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
  3. 解压源码源vim

    tar -zxvf nginx-1.12.0.tar.gz
  4. ls查看解压后的文件centos

    ls
    # 进入该文件
    cd niginx-1.12.0
    # 查看是否有Makefile 这里是没有的,因此要进行编译
  5. 编译,开启nginx状态监测功能浏览器

    ./configure --prefix=/opt/nginx1-12/ --with-http_ssl_module --with-http_stub_status_module

    编译完后该目录中会生成一个Makefile文件

  6. 安装

    make && make install
  7. 启动

    先查看安装的位置,我是安装在/opt/
    tree /opt/nginx1-12
    
    # 启动
    /opt/nginx1-12/sbin/nginx
  8. 关闭重启

    ./nginx -s stop #关闭
    ./nginx -s reload #平滑重启 ,修改了nginx.conf以后,能够不重启服务,加载新的配置
  9. 加入到PATH变量中

    vim /etc/profile
    
    # 在尾添加
    PATH=$PATH:/opt/nginx1-12/sbin/
    # 保存退出
    
    # 读取该文件
    source /etc/profile

布置

详见博客:http://www.javashuo.com/article/p-dwgikfoj-gr.html

负载均衡配置

  • 关键参数

    机器1中内的均衡池

    # 均衡池
      upstream nginx_pools {
              server  192.168.11.37  weight=10;
              server 192.168.11.167  ;
          }
    
      # 反向代理  
    proxy_pass http://nginx_pools;

    机器2内关键参数就直接链接网页

nginx负载均衡的配置
1.实验以下 
准备三台机器
机器1   nginx负载均衡器(发牌的荷官)   192.168.11.158   
    nginx.conf配置以下
    
        #定义nginx负载均衡池,里面默认是轮训算法
        #也能够用weight 权重算法
        #也能够用ip_hash 算法
        
        upstream nginx_pools {
            server  192.168.11.37  weight=10;
            server 192.168.11.167  ;
        }
        server {
            listen       80;
            server_name  192.168.11.158;

            #charset koi8-r;

            #access_log  logs/host.access.log  main;
            #在这里进行反向代理配置
            #192.168.11.158/
            location / {
            proxy_pass http://nginx_pools;
        }
        }




机器2   准备nginx  返回页面数据        192.168.11.37    
    nginx.conf配置以下
            server {
                listen       80;
                server_name  192.168.11.37;
                location / {
                    root   /opt/jd;
                    index  index.html index.htm;
                }
                error_page  404              /40x.html;
                error_page   500 502 503 504  /50x.html;
                location = /50x.html {
                    root   html;
                }
    }

        




机器3   也准备nginx  返回页面数据      192.168.11.167
 server {
        listen       80;
        server_name  192.168.11.167;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

防火墙问题

  • 遇到浏览器访问失败,而本地链接却没问题,检查防火墙是否关闭

    centos7默认已经使用firewall做为防火墙了
    1.关闭防火墙
    systemctl status firewalld #查看防火墙状态
    systemctl stop firewalld    #关闭防火墙
    systemctl disable firewalld#关闭防火墙开机启动
    systemctl is-enabled firewalld.service#检查防火墙是否启动
相关文章
相关标签/搜索