Linux(centos)安装nginx

Linux(centos)安装nginx

转载请注明出处https://www.cnblogs.com/funnyzpc/p/13913023.html

注意,本教程安装环境为centos7,使用nginx官网压缩包编译安装(非rpm或apt),本人亲测有效~

chapter One: 卸载系统自带nginx

  • 停止Nginx软件。
    service nginx stop

  • 删除Nginx的自动启动。
    chkconfig nginx off

  • 删除yum安装
    yum remove nginx

  • 从源头删除Nginx
    rm -rf /usr/sbin/nginx
    rm -rf /etc/nginx
    rm -rf /etc/init.d/nginx

chapter Two: 安装nginx

  • 更新依赖

    • yum update
    • yum install gc gcc gcc-c++ pcre-devel zlib-devel make wget openssl-devel libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools gperftools-devel libatomic_ops-devel perl-ExtUtils-Embed
  • 下载nginx
    wget http://nginx.org/download/nginx-1.18.0.tar.gz

  • 解压
    tar -xvzf nginx-1.18.0.tar.gz

  • 添加nginx用户及用户组

 useradd nginx
 usermod -s /sbin/nologin nginx
  • 编译
  • 进入:cd nginx-1.18.0

  • 帮助项: ./configure --help

  • 编译:./configure --user=nginx --group=nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cpp_test_module --with-cpu-opt=CPU --with-pcre --with-pcre-jit --with-zlib-asm=CPU --with-libatomic --with-debug --with-ld-opt="-Wl,-E"

注意不同版本的nginx其参数可能会有差异,具体请使用--help查看

  • 编译:make && make install

chapter Three: 服务使用

  • start: /usr/sbin/nginx -c /etc/nginx/nginx.conf
  • stop: /usr/sbin/nginx -s stop or kill -9 xxx
  • reload: /usr/sbin/nginx -s reload
  • check status: ps -ef|grep nginx

chapter Four: 防护墙白名单

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

-- 以上安装步骤较为简要,如有谬误之处请留言哈😊--

posted @ 2021-04-05 20:41  funnyZpC  阅读(218)  评论(0编辑  收藏  举报