linux环境下安装nginx

5 篇文章 0 订阅

linux下安装nginx

  1. 确保nginx的依赖项都安装
    yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel

  2. 下载nginx包(nginx-1.14.2.tar.gz),使用winSCP上传到/software目录下

  3. 解压nginx包到当前目录
    [root@localhost software]# tar -zxvf nginx-1.14.2.tar.gz

  4. 进入nginx目录
    [root@localhost software]# cd /software/nginx-1.14.2

  5. 检查配置
    [root@localhost nginx-1.14.2]# ./configure

  6. 编译安装
    [root@localhost nginx-1.14.2]# make & make install
    编安装后会看到下面输出:

    cp conf/nginx.conf ‘/usr/local/nginx/conf/nginx.conf.default’
    test -d ‘/usr/local/nginx/logs’
    || mkdir -p ‘/usr/local/nginx/logs’
    test -d ‘/usr/local/nginx/logs’
    || mkdir -p ‘/usr/local/nginx/logs’
    test -d ‘/usr/local/nginx/html’
    || cp -R html ‘/usr/local/nginx’
    test -d ‘/usr/local/nginx/logs’
    || mkdir -p ‘/usr/local/nginx/logs’
    make[1]: 离开目录“/soft/nginx-1.14.2”
    [1]+ 退出 2 make

  7. 转到目录/usr/local/nginx
    [root@localhost software]# cd /usr/local/nginx

  8. 查看nginx版本
    [root@localhost nginx]# ./sbin/nginx -v
    nginx version: nginx/1.14.2
    解释: 到这里,nginx已成功安装

  9. 直接启动nginx
    [root@localhost nginx]# ./sbin/nginx

  10. 关闭linux防火墙
    [root@192 nginx]# systemctl stop firewalld.service

  11. 浏览器访问 http://192.168.114.134/
    在这里插入图片描述

  12. 查看nginx进程信息
    [root@192 nginx]# ps aux|grep nginx
    root 22594 0.0 0.0 20544 608 ? Ss 10:26 0:00 nginx: master process ./sbin/nginx
    nobody 22595 0.0 0.1 20988 1572 ? S 10:26 0:00 nginx: worker process
    root 22598 0.0 0.0 112724 984 pts/0 R+ 10:27 0:00 grep --color=auto nginx

    说明:
    可以看到nginx由一个主进程和一个工作进程组成

  13. 停止nginx
    [root@192 nginx]# ./sbin/nginx -s stop

  14. 再查看nginx进程信息
    root 22603 0.0 0.0 112724 988 pts/0 R+ 10:30 0:00 grep --color=auto nginx
    说明:
    可以看到没有nginx的进程信息了

  15. nginx重启命令
    [root@192 nginx]# ./sbin/nginx -s reload

  16. nginx的工作进程配置
    nginx.conf文件中
    worker_processes 2;
    将这个地方改为2,然后重启nginx./sbin/nginx -s reload,然后查看nginx进程信息ps aux |grep nginx,显示如下:
    root 22607 0.0 0.1 20544 1368 ? Ss 10:32 0:00 nginx: master process ./sbin/nginx
    nobody 22649 0.0 0.1 20992 1348 ? S 10:37 0:00 nginx: worker process
    nobody 22650 0.0 0.1 20992 1348 ? S 10:37 0:00 nginx: worker process
    root 22652 0.0 0.0 112724 984 pts/0 R+ 10:37 0:00 grep --color=auto nginx

  17. 运行nginx的用户
    nginx.conf文件中
    user root;
    将这个地方改为root,然后重启nginx./sbin/nginx -s reload,然后查看nginx进程信息ps aux |grep nginx,显示如下:
    root 22607 0.0 0.1 20544 1368 ? Ss 10:32 0:00 nginx: master process ./sbin/nginx
    root 22654 0.0 0.1 20976 1428 ? S 10:41 0:00 nginx: worker process
    root 22655 0.0 0.1 20976 1428 ? S 10:41 0:00 nginx: worker process
    root 22657 0.0 0.0 112724 988 pts/0 R+ 10:41 0:00 grep --color=auto nginx

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jackletter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值