• Nginx介绍 安装


    😹 作者: gh-xiaohe
    😻 gh-xiaohe的博客
    😽 觉得博主文章写的不错的话,希望大家三连(✌关注,✌点赞,✌评论),多多支持一下!!!

    🚏 Nginx介绍 安装

    🚀 Nginx版本区别

    常用版本分为四大阵营

    🚄 Nginx概念

    🚬 Nginx介绍

        Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。其特点是占有内存少,并发能力强,事实上Nginx的并发能力在同类型的网页服务器表现较好,中国大陆使用Nginx的网站有:百度、京东、新浪、网易、腾讯、淘宝等

        Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。

    🚬 Nginx的特点

    • 稳定性能强。7*24 小时不间断运行
    • Nginx提供了非常丰富的配置实例
    • 占用内存小并发能力强 50,000个并发 tomcat 1500

    🚒 Nginx安装

    🚬 Window安装

    🚭 1、下载nginx

    下载稳定版本即可:http://nginx.org/en/download.html

    🚭 2、解压

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KQEPIFWB-1662733434136)(Nginx.assets/image-20220909221315948.png)]

    🚭 3、启动
    • 直接双击nginx.exe,双击后一个黑色的弹窗一闪而过

    • 打开cmd命令窗口,切换到nginx解压目录下,输入命令nginx.exe ,回车即可

    🚭 4、检查是否启动成功

    直接在浏览器地址栏输入网址 http://localhost:80 回车,出现以下页面说明启动成功!

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-waGgwWLr-1662733434139)(Nginx.assets/image-20220909221635932.png)]

    🚭 5、关闭nginx

        如果使用cmd命令窗口启动nginx, 关闭cmd窗口是不能结束nginx进程的,可使用两种方法关闭nginx

    • 输入nginx命令 nginx -s stop(快速停止nginx) 或 nginx -s quit(完整有序的停止nginx)
    • 使用taskkill taskkill /f /t /im nginx.exe
      • taskkill是用来终止进程的,
      • /f是强制终止
      • /t终止指定的进程和任何由此启动的子进程。
      • /im示指定的进程名称

    🚬 Linux安装

    🚭 1、安装依赖包
    [root@localhost /]# yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
    
    • 1
    🚭 2、下载Nginx安装包wget
    # 下载wget
    [root@localhost /]# yum install wget
    [root@localhost /]# wget https://nginx.org/download/nginx-1.16.1.tar.gz # 下载的网络链接地址
    
    • 1
    • 2
    • 3
    🚭 3、解压
    [root@localhost /]# tar -zxvf nginx-1.16.1.tar.gz
    
    • 1
    🚭 4、安装到指定目录
    [root@localhost /]# mkdir -p /usr/local/nginx
    [root@localhost /]# cd nginx-1.16.1
    [root@localhost /]# ./configure --prefix=/usr/local/nginx
    
    • 1
    • 2
    • 3
    🚭 5、编译 安装
    [root@localhost /]# cd nginx-1.16.1
    [root@localhost /]# make && make install # 要在nginx目录下
    
    • 1
    • 2
    🚭 6、树形展示结构
    [root@localhost /]# yum install tree 安装树形结构
    [root@localhost nginx]# tree
    .
    ├── client_body_temp
    ├── conf
    │   ├── fastcgi.conf
    │   ├── fastcgi.conf.default
    │   ├── fastcgi_params
    │   ├── fastcgi_params.default
    │   ├── koi-utf
    │   ├── koi-win
    │   ├── mime.types
    │   ├── mime.types.default
    │   ├── nginx.conf
    │   ├── nginx.conf.default
    │   ├── scgi_params
    │   ├── scgi_params.default
    │   ├── uwsgi_params
    │   ├── uwsgi_params.default
    │   └── win-utf
    ├── fastcgi_temp
    ├── html
    │   ├── 50x.html
    │   └── index.html
    ├── logs
    │   ├── access.log
    │   └── error.log
    ├── proxy_temp
    ├── sbin
    │   └── nginx
    ├── scgi_temp
    └── uwsgi_temp
    
    9 directories, 20 files
    [root@localhost nginx]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    🚬 Nginx的目录结构

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bAVkVSB2-1662732524801)(Nginx.assets/image-20220909220753834.png)]

    🚤 Nginx命令

    🚬 查看Nginx版本命令:

    [root@localhost nginx]# cd sbin/
    [root@localhost sbin]# pwd
    /usr/local/nginx/sbin
    [root@localhost sbin]# ./nginx -v # 在nginx的sbin目录下执行
    nginx version: nginx/1.22.0
    
    • 1
    • 2
    • 3
    • 4
    • 5

    🚬 检查一下nginx.conf文件配置的是否有错误

    在启动Nginx服务之前,可以先检查一下conf/nginx.conf文件配置的是否有错误。

    [root@localhost nginx]# cd sbin/
    [root@localhost sbin]# pwd
    /usr/local/nginx/sbin
    [root@localhost sbin]# ./nginx -t # 在nginx的sbin目录下执行
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    🚬 启动Nginx服务命令:

    [root@localhost sbin]# pwd
    /usr/local/nginx/sbin   
    [root@localhost sbin]# ./nginx # 在nginx的sbin目录下执行
    
    • 1
    • 2
    • 3

    🚬 停止Nginx服务命令:

    [root@localhost sbin]# pwd
    /usr/local/nginx/sbin   
    [root@localhost sbin]# ./nginx -s stop # 在nginx的sbin目录下执行
    
    • 1
    • 2
    • 3

    🚬 查看Nginx进程:

    [root@localhost sbin]# ps -ef|grep nginx
    # 两个进程 master 和 worker 第三个进程是执行ps -ef|grep nginx的进程可以忽略
    # 默认两个进程 worker进程可以有多个 修改配置文件 nginx.conf
    root      33011      1  0 18:37 ?        00:00:00 nginx: master process ./nginx
    nobody    33012  33011  0 18:37 ?        00:00:00 nginx: worker process 
    root      33063  27845  0 18:38 pts/1    00:00:00 grep --color=auto nginx
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    🚬 当修改Nginx配置文件后,重新加载配置文件:

    [root@localhost sbin]# pwd
    /usr/local/nginx/sbin   
    [root@localhost sbin]# ./nginx -s reload # 在nginx的sbin目录下执行
    
    • 1
    • 2
    • 3

    🚗 配置Nginx环境变量(重)

    在哪个目录都可以使用nginx命令

    [root@localhost sbin]# vim /etc/profile
    
    PATH=/usr/local/nginx/sbin:$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
    [root@localhost /]# source /etc/profile  # 重新加载
    
    • 1
    • 2
    • 3
    • 4

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HYIoYP61-1662732524802)(Nginx.assets/image-20220909101251547-166273174758911.png)]

    🚲 将Nginx变成系统服务(重)

    🚬 创建服务脚本

    vim /usr/lib/systemd/system/nginx.service

    🚬 脚本内容

    [Unit]
    Description=nginx - web 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
    ExecQuit=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    🚬 重新加载系统服务

    [root@localhost /]# systemctl daemon-reload
    
    • 1

    🚬 启动服务

    [root@localhost /]# systemctl start nginx.service
    
    • 1

    🚬 查看服务

    [root@localhost /]# systemctl status nginx.service
    
    • 1

    🚬 查看进程

    [root@localhost /]# ps -ef | grep nginx
    
    • 1

    🚬 开机启动

    [root@localhost /]# systemctl enable nginx.service 
    
    • 1
  • 相关阅读:
    基于javaweb的企业员工绩效工资管理系统(java+springboot+freemarker+mysql)
    TypeScript学习日志-第二十四天(webpack构建ts+vue3)
    光谱数据处理:1.特征波长优选的不同方法与Python实现
    二分查找的经典样例
    基于matlab的瑞利衰落信道建模和仿真
    理解vue的响应式原理、双向绑定原理、虚拟dom
    SpringBoot banner 样式 自动生成
    【毕业设计】深度学习疫情社交安全距离检测算法 - python opencv cnn
    1.EdgeX实战 Ubuntu18.04搭建运行环境
    基于 Qt UDP通信局域网通信
  • 原文地址:https://blog.csdn.net/gh_xiaohe/article/details/126789676