zoukankan      html  css  js  c++  java
  • Centos7安装nginx(源码安装 不是yum)和安装Stream模块的编译

    nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等。这完全就是抢HAproxy份额的节奏,鉴于nginx在7层负载均衡和web service上的成功,和nginx良好的框架,stream模块前景一片光明。
    ngx_stream_core_module模块
    是模拟反代基于tcp或udp的服务连接,即工作于传输层的反代或调度器

    Nginx版本:1.18.0

    1.下载NGINX稳定发行版

    wget https://nginx.org/download/nginx-1.18.0.tar.gz

    2.解压并切换到安装目录

    tar -zxvf nginx-1.18.0.tar.gz
    cd nginx-1.18.0

    3.编译安装

    默认路径安装

    yum -y install gcc gcc-c++ autoconf automake
    yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
    
    ./configure --with-stream或者

    ./configure --with-stream --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module

    ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-pcre --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_stub_status_module --with-stream



    make
    && make install
    
    
    配置文件路径为/usr/local/nginx/conf/ 
    和启动路径/usr/local/nginx/sbin/nginx
    /usr/local/nginx/sbin/nginx  -s start

    指定nginx.config路径安装

    yum -y install gcc gcc-c++ autoconf automake
    yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
    
    ./configure --prefix=/opt/nginx --sbin-path=/opt/nginx/sbin/nginx --conf-path=/opt/nginx/conf/nginx.conf --with-http_stub_status_module --with-http_gzip_static_module --with-stream
    make
    make install
    cd /opt/nginx
    配置文件路径/opt/nginx/conf/nginx.conf
    和启动路径/opt/nginx/sbin/nginx -s reload

    yum卸载nginx参考链接 https://blog.csdn.net/a704397849/article/details/100569176

    源码安装卸载 sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx

    nginx:未找到命令(command not found)解决方法 加入环境变量:https://www.jianshu.com/p/3aef06a614bc

    service nginx start启动nginx出现Failed to start nginx.service:unit not found   :https://blog.csdn.net/qq_38269316/article/details/82860941

    nginx基本操作命令
    
        systemctl start nginx.service(service nginx start)
    
        systemctl stop nginx.service(service nginx stop)
    
        systemctl reload nginx.service(service nginx restart)
    
        systemctl status nginx.service(service nginx status)

    补充资料

    --prefix=path:设置Nginx的安装路径,不写的话默认是在/usr/local/nginx
    --sbin-path=path:设置Nginx的可执行文件路径,默认路径是prefix/sbin/nginx
    --conf-path=path:设置Nginx配置文件路径,默认路径是prefix/conf/nginx.conf
    --pid-path=path:设置Nginx pid文件路径,默认路径是prefix/logs/nginx.pid
    --error-log-path=path:设置错误日志存放路径,默认路径是prefix/logs/error.log
    --http-log-path=path:设置访问日志存放路径,默认路径是prefix/logs/access.log
    --user=name:设置运行Nginx的用户,默认用户是nobody
    --group=name:设置运行Nginx的用户组,默认用户组是nobody
    --with-http_ssl_module:启用Nginx的SSL功能
    --with-http_realip_module:该模块可以记录原始客户端的IP而不是负载均衡的IP
    --with-http_sub_module:文字内容替换模块,可用于替换全站敏感字等
    --with-http_flv_module:开启对FLV格式文件的支持
    --with-http_mp4_module:开启对MP4格式文件的支持
    --with-http_gzip_module:提供对gzip压缩的支持
    --with-http_stub_status_module:开启Nginx状态监控模块
    --with-pcre:支持正则表达式

    Nginx主配置文件参数详解

    user nginx; #定义运行Nginx的用户
    worker_processes 2;#Nginx所开启的进程数,通常和cpu个数相等或者设置为auto
    worker_cpu_affinity auto; #自动进行CPU亲和设置
    worker_cpu_affinity 0000000000000001 000000000000010 #手动进行CPU亲和设置
    worker_rlimit_nofile 65535; #一个worker进程最多能打开的文件数
    error_log logs/error.log warn; #Nginx服务的错误日志路径与记录级别
    pid /var/run/nginx.pid;
    worker_rlimit_nofile 65535; #设置Nginx进程文件句柄数
    events { worker_connections 10240; #每个进程的并发数 use epoll; }
    http {
    include mime.types; #文件扩展名与文件类型映射表
    default_type application/octet-stream; #默认文件类型
    charset utf-8; #默认字符集
    log_format main #定义日志格式
    access_log logs/access.log main; #访问日志存放路径与日志记录格式,这里main就是上一步log_format所定义的main
    sendfile on;
    tcp_nopush on; #一次传输多个数据包,提高传输效率
    #tcp_nodeley off #与tcp_nopush相反,实时性要求比较高的场景会打开这个
    keepalive_timeout 65; #长连接超时时间为65秒
    gzip on; #打开gzip后通过浏览器开发者工具-网络功能可以看到size大小被压缩了,对文本类型的文件压缩效率最高,可作用于location中
    include /etc/nginx/conf.d/*.conf #conf.d目录下的配置文件也会生效
    server { listen 80; server_name linuxe.cn www.linuxe.cn; #精确匹配优先级最高,支持正则匹配,如果都不匹配则匹配default server access_log logs/access.log main; #单独对主机记录日志 location ~ .*.(jpg|gif|png)$ { gzip on; expires 24h; #开启缓存,如果是取的缓存数据,浏览器开发者工具中返回状态是304 root html; index index.html index.htm; } #error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
    其中main和events都是全局性标签;
    而server标签负责了每个虚拟主机的配置,
    在server标签中还存在localtion标签,可以根据条件匹配来对不同的访问路径做不同的配置,实现URL转发等功能。
    localtion标签有着一个匹配顺序需要注意,这是经常出错的地方,下面是localtion优先级排序示例;
    location = /uri #精确匹配,优先级最高
    location ^~ /uri #普通字符串匹配,不支持正则表达式,当匹配成功后停止其他location匹配,优先级高于正则
    location ~ #区分大小写的正则匹配
    location ~* #不区分大小写的正则匹配
    location /uri #前缀匹配
    location / #通用匹配
    sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx


    重新安装http://blog.chinaunix.net/uid-69994259-id-5845151.html


    已经yum安装的 需要添加第三方模块或者平滑升级时候 参考下面链接
    https://www.136.la/nginx/show-77740.html
    https://blog.csdn.net/qq_37638061/article/details/90581358
    RPM指定版本安装+安装第三方模块
    https://www.cnblogs.com/sky-cheng/p/14621145.html
    https://blog.csdn.net/weixin_30965253/article/details/116893322


    早年同窗始相知,三载瞬逝情却萌。年少不知愁滋味,犹读红豆生南国。别离方知相思苦,心田红豆根以生。
  • 相关阅读:
    使用活字格搭建企业级web应用--办公用品管理系统
    怪兽级性能,用代码玩转Excel!葡萄城强势发布Spread表格组件
    无需编码,轻松搭建企业采购管理软件
    NHibernate变的简单
    Easyui + jQuery表单提交 给 Controller patr1
    Easyui datagrid 批量编辑和提交
    C# 网络编程 Part.1
    提高你开发效率的十五个Visual Studio 2010使用技巧
    System.IO
    C#路径,文件,目录,I/O常见操作
  • 原文地址:https://www.cnblogs.com/shanheyongmu/p/15136999.html
Copyright © 2011-2022 走看看