Linux安装Nginx

10 篇文章 0 订阅
2 篇文章 0 订阅

类型

对于CentOS而言一般分为rpm安装和源码编译安装两种。

rpm

下载对应rpm包

CentOS7为例:

wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.16.0-1.el7.ngx.x86_64.rpm

rpm导入

rpm -ivh nginx-1.16.0-1.el7.ngx.x86_64.rpm

yum安装

yum install nginx

启动、停止、重启及开机启动

systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl enable nginx

默认配置

主配置文件在/etc/nginx/目录下

日志由主配置文件定义,默认在/var/log/nginx

可以通过whereis nginx查看其他配置,其运行结果为

nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/local/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

其中/usr/sbin/nginx是nginx的启动脚本。

编译

安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

安装 PCRE

PCRE 作用是让 Nginx 支持 Rewrite 功能。

  1. 下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

    wget -P /usr/local/src/ http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
    
  2. 解压安装包

    指定解压目录为/usr/local/src

    tar zxvf /usr/local/src/pcre-8.35.tar.gz -C /usr/local/src/
    
  3. 编译

    cd /usr/local/src/pcre-8.35
    ./configure
    make && make install
    
  4. 测试

    pcre-config --version
    

源码

  1. 下载

    wget -P /usr/local/ http://nginx.org/download/nginx-1.17.2.tar.gz
    
  2. 解压

    tar zxvf /usr/local/nginx-1.17.2.tar.gz  -C /usr/local
    
  3. 编译

    ./configure \
     --prefix=/usr/local/nginx \
     --sbin-path=/usr/sbin/nginx \
     --with-pcre=/usr/local/src/pcre-8.35 \
     --conf-path=/etc/nginx/nginx.conf \
     --error-log-path=/var/log/nginx/error.log \
     --http-client-body-temp-path=/var/lib/nginx/body \
     --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
     --http-log-path=/var/log/nginx/access.log \
     --http-proxy-temp-path=/var/lib/nginx/proxy \
     --lock-path=/var/lock/nginx.lock \
     --pid-path=/var/run/nginx.pid \
     --with-debug \
     --with-http_gzip_static_module \
     --with-http_realip_module \
     --with-http_stub_status_module \
     --with-http_ssl_module \
     --with-http_sub_module \
     --with-mail \
     --with-mail_ssl_module
     
     make && make install
    
  4. 测试

    nginx -v
    

开机启动

参考官方文档编写启动脚本/etc/init.d/nginx

chmod a+x /etc/init.d/nginx
systemctl enable nginx
systemctl start nginx

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值