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 版权协议,欢迎转载 转载请附上原文出处链接和本声明,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话