ubnutu系统安装nginx并设置为系统服务
首先安装依赖
apt-get install gcc apt-get install libpcre3 libpcre3-dev apt-get install zlib1g zlib1g-dev sudo apt-get install openssl sudo apt-get install libssl-dev
然后下载解压nginx
cd /usr/local mkdir ./nginx cd ./nginx wget http://nginx.org/download/nginx-1.16.0.tar.gz tar -xvf ./nginx-1.16.0.tar.gz
编译安装nginx
cd ./nginx-1.16.0 ./configure make make install
创建nginx.service文件并赋予权限
cd /lib/systemd/system touch ./nginx.service chmod 777 nginx.service
编辑文件nginx.service
# This file is part of systemd. # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This unit gets pulled automatically into multi-user.target by [Unit] Description=/home/user/service/nginx.sh Compatibility ConditionFileIsExecutable=/home/user/service/nginx.sh After=network.target [Service] Type=forking ExecStart=/home/user/service/nginx.sh TimeoutSec=0 RemainAfterExit=yes #### 添加 #### [Install] WantedBy=multi-user.target Alias=nginx.service
创建nginx.sh文件
cd /home/user/service/
vi ./nginx.sh
内容:
#!/bin/sh -e cd /usr/local/nginx/sbin ./nginx
赋予权限
chmod 677 ./nginx.sh
创建链接
sudo ln -s /lib/systemd/system/nginx.service /etc/systemd/system
设置开机自启
systemctl enable nginx.service
启动服务
systemctl start nginx.service
查看服务状态
systemctl status nginx.service
nginx已启动
浏览器输入本地IP
完成
学习时的痛苦是暂时的 未学到的痛苦是终生的
作者:卷心菜的奇妙历险
本文版权归作者和博客园共有,遵循 CC 4.0 BY-SA 版权协议,欢迎转载 转载请附上原文出处链接和本声明,否则保留追究法律责任的权利。