当前位置: 首页 > news >正文

Linux下源码编译安装Nginx1.24及服务脚本实战

 1、下载Nginx

[root@localhost ~]# wget -c https://nginx.org/download/nginx-1.24.0.tar.gz

2、解压

[root@localhost ~]# tar xf nginx-1.24.0.tar.gz -C /usr/local/src/

3、安装依赖

[root@localhost ~]# yum install gcc gcc-c++ make pcre-devel openssl-devel -y

4、 准备 Nginx 的编译环境,通过./configure 脚本,定义Nginx 安装后的根目录、可执行文件的位置、访问日志和错误日志的路径,以及主进程 PID 文件的存储位置

[root@localhost ~]# cd /usr/local/src/nginx-1.24.0/
[root@localhost nginx-1.24.0]# mkdir -p /var/log/nginx
[root@localhost nginx-1.24.0]# ./configure --prefix=/usr/local/nginx \
> --sbin-path=/usr/sbin/nginx \
> --http-log-path=/var/log/nginx/access.log \
> --error-log-path=/var/log/nginx/error.log \
> --pid-path=/run/nginx.pid

5、编译安装

[root@localhost nginx-1.24.0]# make[root@localhost nginx-1.24.0]# make install

6、编写服务脚本

[root@localhost ~]# vim /etc/systemd/system/nginx.service
[root@localhost ~]# cat /etc/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=mixed
PrivateTmp=true[Install]
WantedBy=multi-user.target

7、重新加载systemd配置,启用并启动服务

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable nginx.service
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /etc/syste                                                                            md/system/nginx.service.
[root@localhost ~]# systemctl start nginx.service

8、检查服务状态

9、测试nginx响应

或者在浏览器访问http:IP,出现以下页面则安装成功

10、测试重载和停止服务 

[root@localhost ~]# systemctl reload nginx.service
[root@localhost ~]# systemctl stop nginx.service

http://www.lryc.cn/news/521591.html

相关文章:

  • 4、dockerfile实现lnmp和elk
  • Portainer.io安装并配置Docker远程访问及CA证书
  • 探索 Transformer²:大语言模型自适应的新突破
  • Flutter 多终端测试 自定义启动画面​​​​​​​ 更换小图标和应用名称
  • rsarsa-给定pqe求私钥对密文解密
  • flutter开发-figma交互设计图可以转换为flutter源代码-如何将设计图转换为flutter源代码-优雅草央千澈
  • Deep4SNet: deep learning for fake speech classification
  • 3 前端: Web开发相关概念 、HTML语法、CSS语法
  • SpringBoot工程快速启动
  • Unity WebGL:本机部署,运行到手机
  • 【线性代数】行列式的概念
  • Android SystemUI——StatusBar视图创建(六)
  • Picocli 命令行框架
  • spring-cloud-starter-gateway 使用中 KafkaAppender的问题
  • 【全套】基于分类算法的学业警示预测信息管理系统
  • Elasticsearch Python 客户端是否与自由线程 Python 兼容?
  • 基于大语言模型的组合优化
  • #CSS混合模式:解决渐变背景下的文字可见性问题
  • Vue2+OpenLayers给标点Feature添加信息窗体(提供Gitee源码)
  • 实战threeJS数字孪生开源 数字工厂
  • 【Python基础篇】——第3篇:从入门到精通:掌握Python数据类型与数据结构
  • 算法3(力扣83)-删除链表中的重复元素
  • HarmonyOS 鸿蒙 ArkTs(5.0.1 13)实现Scroll下拉到顶刷新/上拉触底加载,Scroll滚动到顶部
  • .NET8.0多线程编码结合异步编码示例
  • SpringBoot项目中解决CORS跨域资源共享问题
  • Android string.xml中特殊字符转义
  • 解析传统Workflow、AI Workflow与AI Agent概念,并通过Coze案例探讨利用AI工作流构建应用的实践流程
  • 光谱相机的光谱分辨率可以达到多少?
  • android Recyclerview viewholder统一封装
  • Windows部署NVM并下载多版本Node.js的方法(含删除原有Node的方法)