美文网首页
Centos8 安装nginx1.20.2

Centos8 安装nginx1.20.2

作者: 云顶天宫写代码 | 来源:发表于2022-01-10 20:07 被阅读0次
    1. 安装基本
    #gcc安装,nginx源码编译需要
    yum install gcc-c++
    
    #PCRE pcre-devel 安装,nginx 的 http 模块使用 pcre 来解析正则表达式
    yum install -y pcre pcre-devel
    
    #zlib安装,nginx 使用zlib对http包的内容进行gzip
    yum install -y zlib zlib-devel libxml2 libxml2-dev libxslt-devel
    
    #OpenSSL 安装,强大的安全套接字层密码库,nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http)
    yum install -y openssl openssl-devel
    

    下载nginx 并解压

    wget http://nginx.org/download/nginx-1.20.1.tar.gz
    
    tar xf nginx-1.20.1.tar.gz
    cd nginx-1.20.1
    

    带上stream 初始化

    ./configure --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=/run/nginx.pid --lock-path=/run/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-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_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-http_auth_request_module --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-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --with-stream
    

    编译

    make && make install
    

    注意 生成nginx 主要路径
    usr/sbin/nginx
    /etc/nginx/nginx.conf

    添加自启动

     mkdir /var/lib/nginx/
     mkdir /var/lib/nginx/tmp/
     mkdir /var/lib/nginx/tmp/client_body/  /var/lib/nginx/tmp/proxy /var/lib/nginx/tmp/fastcgi /var/lib/nginx/tmp/uwsgi /var/lib/nginx/tmp/scgi
    
    vim /lib/systemd/system/nginx.service
    

    加入以下内容

    [Unit]
    
    Description=nginx service
    
    After=network.target
    
    [Service]
    
    Type=forking
    
    ExecStart=/usr/sbin/nginx         //nginx的可执行路径
    
    ExecReload=/usr/sbin/nginx -s reload 
    ExecStop=/usr/sbin/nginx -s stop
    
    PrivateTmp=true
    
    [Install]
    
    WantedBy=multi-user.target
    

    保存后

    chmod +x /usr/lib/systemd/system/nginx.service
    systemctl daemon-reload
    systemctl enable nginx.service
    systemctl start nginx.service  
    
    # systemctl start nginx.service  启动nginx服务
    
    # systemctl stop nginx.service           停止服务
    
    # systemctl restart nginx.service       重新启动服务
    
    # systemctl list-units --type=service    查看所有已启动的服务
    
    # systemctl status nginx.service          查看服务当前状态
    
    # systemctl enable nginx.service          设置开机自启动
    
    # systemctl disable nginx.service        停止开机自启动
    

    相关文章

      网友评论

          本文标题:Centos8 安装nginx1.20.2

          本文链接:https://www.haomeiwen.com/subject/oafvcrtx.html