zoukankan      html  css  js  c++  java
  • 源码安装Nginx以及用systemctl管理

    一、源码安装Nginx:

    • 先安装gcc编译器(安装过的可以忽略)

       [root@localhost ~]# yum -y install gcc gcc-c++ wget
      
    • 进入src目录

       [root@localhost ~]# cd /usr/local/src/
      
    • 下载 nginx软件包

       [root@localhost src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
      
    • 解压

       [root@localhost src]# tar -zxvf nginx-1.14.0.tar.gz
      
    • 进入nginx-1.14.0目录

       [root@localhost src]# cd nginx-1.14.0/
      
    • 安装依赖

       [root@localhost nginx-1.14.0]# yum -y install openssl openssl-devel
      
    • ./configure软件配置与检查

       [root@localhostnginx-1.14.0]#./configure--prefix=/usr/local/nginx --with-http_ssl_module
      
    • 安装

       [root@localhost nginx-1.14.0]# make
       [root@localhost nginx-1.14.0]# make install
      
    • 启动nginx

       [root@localhost nginx-1.14.0]#cd /usr/local/nginx/sbin
       [root@localhost nginx-1.14.0]#./nginx
      

    查看是否启动成功

        [root@localhost nginx-1.14.0]# ps aux |grep nginx    
    

    二、systemctl管理:

    • 创建配置文件
      源码安装的nginx在/etc/systemd/system/multi-user.target.wants/目录下是没有nginx.service这个文件的,所以要新建

       [root@localhost nginx-1.14.0]#vim /usr/lib/systemd/system/nginx.service
      
    • 写入内容(全部复制进去,然后修改)

       [Unit]
       Description=nginx - high performance web server
       Documentation=http://nginx.org/en/docs/
       After=network-online.target remote-fs.target nss-lookup.target
       Wants=network-online.target
       
       [Service]
       Type=forking
       PIDFile=/var/run/nginx.pid
       ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
       ExecReload=/bin/kill -s HUP $MAINPID
       ExecStop=/bin/kill -s TERM $MAINPID
       
       [Install]
       WantedBy=multi-user.target
      
    • 修改 [Service]内容

        将:
            ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf,
        改为:
            ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
      
    • 设置开机启动

          [root@localhost nginx-1.14.0]# systemctl enable nginx.service
      
    • 关闭之前启动的nginx服务

          [root@localhost nginx-1.14.0]# pkill -9 nginx
      
    • 重载修改过的所有配置文件

           [root@localhost nginx-1.14.0]#systemctl daemon-reload
      
    • 重新启动nginx服务

           [root@localhost nginx-1.14.0]#systemctl start nginx
      

      最后可以用浏览器访问自己虚拟机的IP:192.168.xxx.xx

  • 相关阅读:
    四则运算二
    学习进度
    软件工程个人作业01
    观《构建之法》有感
    软件工程概论课程引言课后作业
    编写一个程序,此程序在运行时要求用户输入一个 整数,代表某门课的考试成绩,程序接着给出“不及格”、“及格”、“中”、“良”、“优”的结论。
    软件需求与分析课堂讨论一
    软件需求模式阅读笔记一
    我们应当怎么做需求分析
    问题账户需求分析
  • 原文地址:https://www.cnblogs.com/MisterZZL/p/9609439.html
Copyright © 2011-2022 走看看