码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Ubuntu 20.04 源码安装 nginx


    Ubuntu 20.04 源码安装 nginx

    • 1. Ubuntu 20.04 源码安装 nginx
    • 2. nginx 源码编译
      • 2.1 依赖安装
      • 2.2 配置目录
      • 2.3 编译安装
    • 3. 启动nginx
    • 4. 创建系统服务
      • 4.1 官方系统服务配置
      • 4.2 apt install nginx 安装系统配置
      • 4.3 参考
      • 4.4 编辑 nginx.service
    • 5. 查看日志

    1. Ubuntu 20.04 源码安装 nginx

    2. nginx 源码编译

    # cat /etc/issue
    Ubuntu 20.04.4 LTS \n \l
    
    • 1
    • 2

    2.1 依赖安装

    apt-get update
    
    • 1
    apt-get install -y make gcc libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev
    
    • 1
    wget https://nginx.org/download/nginx-1.20.2.tar.gz
    cd nginx-1.20.2/
    
    • 1
    • 2

    2.2 配置目录

    • --prefix 安装目录
    ./configure --prefix=/etc/nginx
    
    • 1

    2.3 编译安装

    make
    make install
    
    • 1
    • 2

    3. 启动nginx

    /etc/nginx/sbin/nginx
    
    • 1
    ./nginx 启动  
    ./nginx -s stop 快速停止 
    ./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求 
    ./nginx -s reload 重新加载配置
    
    • 1
    • 2
    • 3
    • 4

    4. 创建系统服务

    4.1 官方系统服务配置

    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network-online.target remote-fs.target nss-lookup.target
    Wants=network-online.target
    
    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t
    ExecStart=/usr/sbin/nginx
    ExecReload=/usr/sbin/nginx -s reload
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    4.2 apt install nginx 安装系统配置

    # cat /lib/systemd/system/nginx.service
    [Unit]
    Description=nginx - high performance web server
    Documentation=https://nginx.org/en/docs/
    After=network-online.target remote-fs.target nss-lookup.target
    Wants=network-online.target
    
    [Service]
    Type=forking
    PIDFile=/var/run/nginx.pid
    ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
    ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
    ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"
    
    [Install]
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    4.3 参考

    [Unit]
    Description=A high performance web server and a reverse proxy server
    After=network.target
    
    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
    ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
    ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
    ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
    TimeoutStopSec=5
    KillMode=mixed
    
    [Install]
    WantedBy=multi-user.target
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    4.4 编辑 nginx.service

    vim /lib/systemd/system/nginx.service
    
    • 1
    [Unit]
    Description=nginx web server
    After=network-online.target
    [Service]
    Type=forking
    PIDFile=/etc/nginx/logs/nginx.pid
    ExecStartPre=/etc/nginx/sbin/nginx -t -c /etc/nginx/conf/nginx.conf
    ExecStart=/etc/nginx/sbin/nginx -c /etc/nginx/conf/nginx.conf
    ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /etc/nginx/logs/nginx.pid)"
    ExecStop=/bin/sh -c "/bin/kill -s QUIT $(/bin/cat /etc/nginx/logs/nginx.pid)"
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
    [Install]
    WantedBy=multi-user.target
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    systemctl daemon-reload
    systemctl start nginx.service
    systemctl status nginx.service
    systemctl enable nginx.service
    systemctl reload nginx.service
    
    • 1
    • 2
    • 3
    • 4
    • 5

    5. 查看日志

    journalctl -f -u nginx.service
    
    • 1
  • 相关阅读:
    SpringCloud OpenFeign--声明式WebService 客户端
    2021年03月 Scratch(二级)真题解析#中国电子学会#全国青少年软件编程等级考试
    MySQL---three 多表查询与事务的操作
    Python实现---南邮离散数学实验三:盖住关系的求取及格的判定
    Python算法练习 10.15
    (JVM)MAT 与 JProfiler 的 GC Roots 溯源
    1、什么是复杂度?
    《向量数据库指南》——向量数据库会是 AI 的“iPhone 时刻”吗?
    Python 对象表现得像函数
    【RocketMq 系列】RocketMq 入门教程
  • 原文地址:https://blog.csdn.net/u010953692/article/details/128207614
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号