【服务器环境搭建-Centos7】Nginx1.16.1 安装(编译源码)

nginx官网不同版本下载地址:http://nginx.org/download/

我使用的是nginx-1.9.9.tar.gz

  1. 安装其他支持软件
    • 可以使用rpm –q xxx   查询库是否已经安装成功
    • gcc、make工具
    • rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )
    • gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
    • ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )
    • yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel pcre*
  2. 支持Rewrite(

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

    使用yum源安装: yum -y install pcre*

    或使用wget方式安装
    
    1,下载 PCRE 安装包
    [root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
    2、解压安装包:
        [root@bogon src]# tar zxvf pcre-8.35.tar.gz
    3、进入安装包目录
        [root@bogon src]# cd pcre-8.35
    4、编译安装 
        [root@bogon pcre-8.35]# ./configure
        [root@bogon pcre-8.35]# make && make install
    5、查看pcre版本
        [root@bogon pcre-8.35]# pcre-config --version

     

  3. 源码安装nginx1.16.1
    1. 切换到root目录下  
    2. 下载:http://nginx.org/download/nginx-1.16.1.tar.gz
    3. 解压缩 tar -zxvf nginx-1.16.1.tar.gz
    4. 编译安装
      1. cd nginx-1.16.1
      2. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
        这里也可以添加其他模块,例如:rewrit模块(--with-pcre)  --prefix指定安装的目录  
        --with-http_stub_status_module启用状态统计   
      3. 如果是使用wget方式则configure时,需要指定pcre 

         

        ./configure --with-http_stub_status_module  --prefix=/usr/local/nginx  --with-http_ssl_module  --with-stream

         

      4. make && make install
    5. 检测配置或安装是否成功:/usr/local/nginx/sbin/nginx -t

      如果出现下列信息,则标识安装或配置成功

       

      the configuration file /usr/local/nginx/conf/nginx.conf syntax is othe configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

       

    6. 启动,停止nginx服务

      1

      2

      #/usr/local/nginx/sbin/nginx

      #/usr/local/nginx/sbin/nginx -s stop

    7. nginx启动好后启动tomcat,此时输入http://主机ip地址即可看到“My web!” 
    8. 在/etc/profile 添加nginx的path全局环境变量,则可以直接使用nginx命令
    9. 在/etc/profile 中加入:

      export NGINX_HOME=/usr/local/nginx
      export PATH=$PATH:$NGINX_HOME/sbin
    10. 执行 source /etc/profile ,使配置文件生效。

    11. 设置开机启动服务

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl enable nginx  加入开机启动

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值