nginx的基本安装与服务器配置

Nginx服务配置

安装到服务器

  1. 传输Nginx的tar包到root目录下

  2. 输入命令tar zxvf nginx-****.tar.gz 解压缩

  3. 切换到解压目录中

  4. 配置yum镜像阿里云源,推荐文章:https://blog.csdn.net/LONG_Yi_1994/article/details/141276315

  5. 安装C语言的编译器yum install -y gcc

  6. 依配置检查命令 ./configure --prefix=/usr/local/nginx

  7. 安装per库 yum install -y pcre pcre-devel

  8. 安装zlib库yum install -y zlib zlib-devel

  9. 安装make库sudo yum install make

  10. 安装制作命令先输入make再输入 make install

  11. 切换目录cd /usr/local/nginx/sbin

  12. 执行运行命令 ./nginx

  13. sudo systemctl stop firewalld # 停止firewalld服务

    sudo systemctl disable firewalld # 禁用firewalld服务,使其不会开机自启

安装成系统服务

  1. 创建服务脚本vi /usr/lib/systemd/system/nginx.service

  2. 编辑内容

    nginx 复制代码
    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s stop
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
  3. 关闭nginx服务

    ./nginx -s stop

  4. 重启加载系统服务

    systemctl daemon-reload

  5. 查看系统中存在的服务中是否包含nginx

    ps -ef | grep nginx

  6. 单独开启和查看nginx服务命令状态

    systemctl start nginx

    systemctl status nginx

  7. 开机启动nginx服务

    systemctl enable nginx

  8. 验证开机启动是否成功,显示enabled成功

    systemctl is-enabled nginx

  9. 重启服务器(不一定要搞这一步),reboot

补充操作命令

nginx 复制代码
./nginx #启动
./nginx -s stop #快速停止
./nginx -s quit #优雅关闭,等待客户端各项业务处理完毕后再关闭
./nginx -s reload #重置加载配置
相关推荐
ascarl20103 小时前
记录一下es节点掉线后修复好了的情况
运维·jenkins
阿巴~阿巴~3 小时前
JsonCpp:C++ JSON处理利器
linux·网络·c++·json·tcp·序列化和反序列化
ao_lang3 小时前
数据链路层
linux·服务器·网络
safestar20123 小时前
Elasticsearch深度实战:从分布式原理到生产环境踩坑全记录
运维·搜索引擎·全文检索·es
z***3353 小时前
【MySQL系列文章】Linux环境下安装部署MySQL
linux·mysql·adb
偶像你挑的噻4 小时前
13-Linux驱动开发-中断子系统
linux·驱动开发·stm32·嵌入式硬件
小兔薯了4 小时前
7. LNMP-wordpress
android·运维·服务器·数据库·nginx·php
福尔摩斯张4 小时前
Linux进程间通信(IPC)机制深度解析与实践指南
linux·运维·服务器·数据结构·c++·算法
cookies_s_s5 小时前
项目--协程库(C++)前置知识篇
linux·服务器·c++
不过普通话一乙不改名5 小时前
Linux 网络发包的极致之路:从普通模式到 AF_XDP ZeroCopy
linux·运维·网络