centos下安装和配置nginx

Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个 BSD-like 协议下发行。其特点是占有内存少,并发能力强等。

1. 安装前

因为nginx是c编写的需要c的lib库,g++、gcc、openssl-devel、pcre-devel和zlib-devel等

  • gcc:安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc。
    $   yum install gcc-c++
    
  • PCRE:PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
    $  yum install -y pcre pcre-devel
    
  • zlib:zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
    $   yum install -y zlib zlib-devel
    
  • OpenSSL:OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
    nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装OpenSSL库。
    $   yum install -y openssl openssl-devel
    

2. 安装

  • 下载
    官网下载
    或者
    $   wget http://nginx.org/download/nginx-1.16.1.tar.gz
    
  • 解压nginx压缩包
    $   tar -zxvf nginx-1.16.1.tar.gz
    
    此时会产生一个nginx-1.16.1 目录,这时进入nginx-1.16.1 目录
    $   cd  nginx-1.16.1
    
    接下来安装,使用–prefix参数指定nginx安装的目录,make、make install安装
    #默认安装在/usr/local/nginx   
    $  ./configure  & make & make install
    $  make
    $  make install
    
      # 跑出来的信息
     nginx path prefix: "/usr/local/nginx"
      nginx binary file: "/usr/local/nginx/sbin/nginx"
      nginx modules path: "/usr/local/nginx/modules"
      nginx configuration prefix: "/usr/local/nginx/conf"
      nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
      nginx pid file: "/usr/local/nginx/logs/nginx.pid"
      nginx error log file: "/usr/local/nginx/logs/error.log"
      nginx http access log file: "/usr/local/nginx/logs/access.log"
      nginx http client request body temporary files: "client_body_temp"
      nginx http proxy temporary files: "proxy_temp"
      nginx http fastcgi temporary files: "fastcgi_temp"
      nginx http uwsgi temporary files: "uwsgi_temp"
      nginx http scgi temporary files: "scgi_temp"
    
    如果没有报错,顺利完成后,最好看一下nginx的安装目录
    $   whereis nginx
    
    此时进入/usr/local/nginx/sbin目录,执行命令,启动nginx
    $   ./nginx
    
    其它常用命令
    $   ./nginx -v              		  # 查看 Nginx 版本
    $   ./nginx -s reload       # 重新载入配置文件
    $   ./nginx -s reopen     # 重启 Nginx
    $   ./nginx -s stop          # 停止 Nginx
    $   ./nginx -t                    # 检查配置文件nginx.conf的正确性
    

现在在浏览器的地址栏输入ip地址,就会出现nginx的标志啦。

3. 安装后的配置

nginx配置服务器跳转实现一个域名访问两台服务器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值