Ubuntu 编译安装LNMP (一) 安装nginx

拜拜、爱过 提交于 2021-01-23 06:42:48

创建用户组    groupadd www(组名)

创建用户   useradd -m -g www(组名) dev(用户名)         ||    useradd -m -g www(组名) -s /bin/bash  dev    (省去下一步)

修改用户shell  m -g  vim /etc/pasword   

切换用户  su 

改变文件的属主   chown -R www.dev software/

一、安装nginx

1.安装编译需要用到的库和工具

apt-get install build-essential libtool gcc automake autoconf make

2.安装pcre,支持重写rewrite功能

源码下载地址:https://ftp.pcre.org/pub/pcre/

wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz

tar -zxvf pcre-8.44.tar.gz

cd pcre-8.44/

./configure

make && make install

3.安装zlib, 支持gzip压缩

源码下载地址:http://zlib.net

wget http://zlib.net/zlib-1.2.11.tar.gz

tar -zxvf zlib-1.2.11.tar.gz

cd zlib-1.2.11

./configure 

make && make install

4.安装ssl

源码地址:https://www.openssl.org/source/

wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz

tar -zxvf openssl-1.1.1g.tar.gz

cd openssl-1.1.1g

./config

make && make install

安装运行NIGINX:

1. 下载nginx源码

源码地址:http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.18.0.tar.gz

tar -zxvf nginx-1.18.0.tar.gz

cd nginx-1.18.0

./configure --sbin-path=/usr/local/nginx/sbin/nginx --pid-path=/usr/local/nginx/sbin/nginx.pid --with-http_ssl_module --with-pcre=/opt/pcre-8.44 --with-zlib=/opt/zlib-1.2.11 --with-openssl=/opt/openssl-1.1.1g

make && make install

二、添加为系统服务
1、创建服务文件
    vim /lib/systemd/system/nginx.service
2、文件内容及说明
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target

3、 说明
    [Unit]        // 服务的说明
    Description    // 描述服务
    After        // 依赖,当依赖的服务启动之后再启动自定义的服务
    [Service]        // 服务运行参数的设置
    Type=forking    // 后台运行的形式
    ExecStart        // 服务的具体运行命令(需要根据路径适配)
    ExecReload        // 重启命令(需要根据路径适配)
    ExecStop        // 停止命令(需要根据路径适配)
    PrivateTmp=True    // 表示给服务分配独立的临时空间
    // 注意:启动、重启、停止命令全部要求使用绝对路径
     
    [Install]    // 服务安装的相关设置,可设置为多用户

启动命令为
service nginx start
systemctl start nginx
systemctl start nginx.service

常用命令:
systemctl start nginx
systemctl start nginx.service
systemctl stop nginx
systemctl reload nginx
systemctl restart nginx
systemctl status nginx

添加为开机启动:
systemctl enable nginx.service
systemctl enable nginx

移除开机启动:
systemctl disable nginx.service
systemctl disable nginx

查看开机启动项(nginx 不显示

    在软件源列表sources.list(该文本的位置在/etc/apt/sources.list)文件中的末尾添加如下内容:
    deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
    3、更新apt-get,在终端输入sudo apt-get update
    在这里插入图片描述
    4、完成更新后,重新安装sysv-rc-conf,在终端输入sudo apt-get install sysv-rc-conf,即可成功安装。
    5、安装完成后执行sysv-rc-conf --list 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!