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 #重置加载配置
相关推荐
Lethehong35 分钟前
在 CentOS 7 上搭建 OpenTenBase 集群:从源码到生产环境的全流程指南
linux·运维·centos·tdsql·opentenbase·腾讯云数据库
Hard but lovely41 分钟前
vim的使用
linux·编辑器·vim
yuxb731 小时前
集群与负载均衡:HAProxy 与 Nginx 实践
运维·nginx·负载均衡
知白守黑2671 小时前
KVM虚拟化
linux·运维·架构·centos
G_H_S_3_3 小时前
【网络运维】Linux 文本搜索利器: grep命令
linux·运维·网络·操作文本
程序员 _孜然12 小时前
Ubuntu/Debian修改网卡名字enP3p49s0为eth0
linux·运维·驱动开发·嵌入式硬件·ubuntu·debian
IDIOT___IDIOT12 小时前
Linux mount 命令
linux·运维·服务器
暗流者12 小时前
AAA 服务器与 RADIUS 协议笔记
运维·服务器·笔记
锐策12 小时前
Git checkout 与 Git reset 核心区别解析(分支与版本关联逻辑)
运维·git
CTRA王大大13 小时前
【golang】制作linux环境+golang的Dockerfile | 如何下载golang镜像源
linux·开发语言·docker·golang