• CentOS 中下载安装Nginx


    CentOS 中安装Nginx

    版本区别

    常用版本分为

    • Nginx开源版

    http://nginx.org/

    • Nginx plus 商业版

    https://www.nginx.com

    • openresty

    http://openresty.org/cn/

    虚拟机 CentOS7.6

    Nginx安装

    下载

    https://nginx.org/en/download.html

    传到虚拟机中并解压缩

    编译安装

    ./configure --prefix=/usr/local/nginx

    make

    make install

    如果出现警告或报错

    提示:

    ./configure: error: the HTTP rewrite module requires the PCRE library.
    You can either disable the module by using --without-http_rewrite_module
    option, or install the PCRE library into the system, or build the PCRE library
    statically from the source with nginx by using --with-pcre= option.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    安装perl库

    yum install -y pcre pcre-devel

    提示:

    ./configure: error: the HTTP gzip module requires the zlib library.
    You can either disable the module by using --without-http_gzip_module
    option, or install the zlib library into the system, or build the zlib library
    statically from the source with nginx by using --with-zlib= option.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    安装zlib库

    yum install -y zlib zlib-devel

    启动Nginx

    进入安装好的目录/usr/local/nginx/sbin

    ./nginx 启动 
    ./nginx -s stop 快速停止
    ./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求
    ./nginx -s reload 重新加载配置
    
    • 1
    • 2
    • 3
    • 4

    关于防火墙

    关闭防火墙

    systemctl stop firewalld.service

    禁止防火墙开机启动

    systemctl disable firewalld.service

    放行端口

    firewall-cmd --zone=public --add-port=80/tcp --permanent

    重启防火墙

    firewall-cmd --reload

    安装成系统服务

    创建服务脚本

    vi /usr/lib/systemd/system/nginx.service

    服务脚本内容

    [Unit]
    Description=nginx -  web server
    After=network.target remote-fs.target nss-lookup.target
      
    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s stop
    ExecQuit=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true
      
    [Install]
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    重新加载系统服务

    systemctl daemon-reload

    启动服务

    systemctl start nginx.service

    开机启动

    systemctl enable firewalld.service

  • 相关阅读:
    明天就是PMP考试了(6月25日),这些大家都了解了吗?
    【OpenCV 例程200篇】202. 查表快速替换(cv.LUT)
    阿里云国际站:阿里云linux扩充磁盘大小常见问题
    idea禁用双击ctrl
    龙讯旷腾:如何建立基于第一性原理的正向研发模式,原子级计算伴随的时间和空间尺度增长将带来的变革
    北京筑龙&京东安全:为采购与招标平台筑起“防火墙”
    大厂this面试题和箭头函数的this指向
    sci论文写法
    spark集群问题汇总
    Docker打包python镜像(Windows)
  • 原文地址:https://blog.csdn.net/qq_35543206/article/details/132840760