Nginx初尝试
https://blog.csdn.net/qq_45408390/article/details/119457559 (笔记)
安装nginx(过程中我遇到的问题)
都执行过的命令(主要还是环境没有配置好)
yum -y install gcc-c++
yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
yum -y install openssl openssl-devel
启动nginx的时候报出来的问题:
nginx: [emerg] getpwnam("nginx") failed
解决问题的办法:https://www.cnblogs.com/dotnetcrazy/p/11304783.html
创建web项目并且部署,参考网址:https://www.bilibili.com/video/av76118959?p=5
Nginx实战应用:
这里我搭建了一个小项目,使用的是springboot框架
项目的架构图:
这里使用了一个注册中心,和两个服务端。
部分代码展示:
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 | package com.qqq.controller; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; /** * 描述 TODO * 作者 qqq * 创建时间 2020/10/6 21:58 **/ @RestController @Slf4j public class PaymentController { @Value ( "${server.port}" ) private String serverPort; /** * 浏览器:http://localhost:8001/index * @return */ @GetMapping (value = "/index" ) public String getPaymentByID(){ System.out.println( "今天的天气真好呀!!!" ); return "端口:" +serverPort; } } |
package com.qqq.controller; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; /** * 描述 TODO * 作者 qqq * 创建时间 2020/10/6 21:58 **/ @RestController @Slf4j public class PaymentController { @Value("${server.port}") private String serverPort; /** * 浏览器:http://localhost:8082/index * @return */ @GetMapping(value = "/index") public String getPaymentByID(){ System.out.println("昨天的天气真好呀!!!"); return "端口:"+serverPort; } }
代码写完之后,我们启动Nginx:
Nginx Windows系统的启动命令:nginx.exe
Nginx Windows系统重新加载配置文件命令:nginx -s reload
然后启动项目,项目启动之后,我们发现之前的访问方式不能够进行正常的访问了,因为被我们配置的Nginx拦截了,所以就不能正常访问了
然后我们直接访问localhost:就会交替的出现我们想要的结果,当然,我们也可以通过查看后台日志,进行观察。当然使用:http://127.0.0.1/index 进行访问也是可以的。
· Blazor Hybrid适配到HarmonyOS系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 解决跨域问题的这6种方案,真香!
· 分享4款.NET开源、免费、实用的商城系统
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库
2020-01-03 微服务项目-lombok插件的使用