[学习笔记] Ubuntu16.04编译安装nginx

更新系统安装源

sudo apt update

安装需要的依赖

sudo apt install build-essential
sudo apt install libtool
sudo apt install libpcre3 libpcre3-dev
sudo apt install zlib1g-dev
sudo apt-get install openssl libssl-dev

下载nginx源码包进行编译以及安装安装

wget http://nginx.org/download/nginx-1.13.2.tar.gz
tar zxvf nginx-1.13.2.tar.gz
cd nginx-1.13.2
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
make
sudo make install

在系统服务目录里创建nginx.service文件

sudo vi /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 -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

设置开机启动

  • systemctl enable nginx.service

启动nginx服务

  • systemctl start nginx.service 


查看服务当前状态

  • systemctl status nginx.service

重新启动服务

  • systemctl restart nginx.service 

查看所有已启动的服务

  • systemctl list-units --type=service

你可能感兴趣的:([学习笔记] Ubuntu16.04编译安装nginx)