nginx入门使用

一、官网下载安装文件

官网下载地址:http://nginx.org/en/download.html

image-20210522093622850

二、nginx解压安装

下载后上传到Linux服务器上解压

# 解压文件
[root@localhost applications]# tar -zxvf nginx-1.20.0.tar.gz

安装指令步骤

注意:mark指令需要gcc环境

如果没有gcc环境,需要安装gcc:yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel make cmake gcc gcc-c++

# 执行配置文件,完成自动配置
[root@localhost nginx-1.20.0]# ./configure 

# 编译安装源文件(需要gcc环境)
[root@localhost nginx-1.20.0]# make
[root@localhost nginx-1.20.0]# make install

# 查询是否安装完成(查看是否存在,显示具体路径,则安装成功)
[root@localhost nginx-1.20.0]# whereis nginx
nginx: /usr/local/nginx

三、nginx启动

# 进入安装完成后的目录
[root@localhost nginx-1.20.0]# cd /usr/local/nginx
# 启动nginx(没有消息返回,则代表启动成功)
[root@localhost nginx]# sbin/nginx 
# 开放80端口号
[root@localhost nginx]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
# 重载防火墙配置
[root@localhost nginx]# firewall-cmd --reload
success

访问IP地址,查看启动状态

image-20210522104451266

四、nginx常用命令

# 启动
[root@localhost nginx]# sbin/nginx
# -s quit是正常停止。
[root@localhost nginx]# sbin/nginx -s quit
# -s stop是强制停止
[root@localhost nginx]# sbin/nginx -s stop
# 启动状态下重新加载配置文件
[root@localhost nginx]# sbin/nginx -s reload
# 查看nginx进程
[root@localhost nginx]# ps aux|grep nginx

五、nginx实战演示配置管理

5.1、打包生产springboot的jar包

打包生产hello1.jar

创建springboot项目,编写HelloController类

package com.ndemo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("hello")
    public String hello(){
        return "hello1";
    }
}

修改打包的项目名称

image-20210522113025741

打包生产hello2.jar

修改项目HelloController类的返回值和项目名称

image-20210522113317993

image-20210522113400643

5.2、部署项目:

把得到的两个jar包上传到Linux上并启动

image-20210522113704970

启动hello1.jar(默认8080端口)

image-20210522114535144

再开启一个远程连接,启动hello2.jar(指定8081端口)

image-20210522114743364

5.3、配置nginx的反向代理和负载均衡

修改nginx的配置文件

[root@localhost nginx]# vim conf/nginx.conf

image-20210522120926458

重载nginx的配置文件

[root@localhost nginx]# sbin/nginx -s reload

5.4、访问查看结果

image-20210522121255191

刷新页面
image-20210522121332551

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Main12138

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值