vue.js项目在nginx上部署:使spring后端记录真实ip地址
2023-09-14 08:59:32 时间
一,查看后端的访问日志:
[web@blog logs]$ tail -100 accesslog2021-10-06.log 127.0.0.1 - 0.004 [06/Oct/2021:15:35:20 +0800] GET /home/home HTTP/1.0 200 97 http://store.lhdtest.net/ Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36
因为没有做真实IP的配置,
所以后端的ip记录下来后都是127.0.0.1
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,nginx配置
[root@blog conf.d]# more storeweb.conf server { listen 80; server_name store.lhdtest.net; root /data/store/web/html; index index.html; location /api { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://localhost:10800; proxy_redirect off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Ngnix-Proxy true; } location / { try_files $uri $uri/ /index.html; } access_log /data/logs/nginxlogs/store_web.access_log; error_log /data/logs/nginxlogs/store_web.error_log; }
说明:
proxy_set_header X-Real-Ip $remote_addr;
这条命令负责把真实IP传递到后端
三,tomcat的访问日志配置:
application.yml
#server server: port: 10800 error: include-stacktrace: always #内嵌tomcat日志 tomcat: accesslog: buffered: true directory: /data/store/back/logs enabled: true file-date-format: yyyy-MM-dd pattern: '%{X-Real-Ip}i %l %T %t %r %s %b %{Referer}i %{User-Agent}i' prefix: accesslog rename-on-rotate: false request-attributes-enabled: false rotate: true suffix: .log
四,测试效果:
访问页面后查看tomcat的访问日志
[web@blog logs]$ tail accesslog2021-10-08.log 124.200.178.99 - 0.145 [08/Oct/2021:10:52:00 +0800] GET /home/home HTTP/1.0 200 97 http://store.lhdtest.net/ Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36(KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 124.200.178.99 - 0.006 [08/Oct/2021:10:52:02 +0800] GET /home/home HTTP/1.0 200 97 http://store.lhdtest.net/ Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36(KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 124.200.178.99 - 0.004 [08/Oct/2021:10:52:04 +0800] GET /home/home HTTP/1.0 200 97 http://store.lhdtest.net/ Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36(KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 124.200.178.99 - 0.004 [08/Oct/2021:10:52:06 +0800] GET /home/home HTTP/1.0 200 97 http://store.lhdtest.net/ Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36(KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 124.200.178.99 - 0.004 [08/Oct/2021:10:53:27 +0800] GET /home/home HTTP/1.0 200 97 http://store.lhdtest.net/ Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36(KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36
可见已可以记录真实IP
五,查看nginx版本:
[root@centos8 nginx-1.18.0]# /usr/local/soft/nginx-1.18.0/sbin/nginx -v nginx version: nginx/1.18.0
六,查看spring boot版本:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.5.4)
相关文章
- spring boot拦截器和过滤器_java拦截器的作用
- Spring 全家桶之 Spring Boot 2.6.4(八)- 嵌入式 Servlet 容器(Part A)
- vue 加载页面时触发时间_Vue 刷新页面时会触发事件吗「建议收藏」
- Spring Boot + @Async = 王炸!!
- SSO 基于token vue + element ui spring boot前后端分离
- spring注解有哪些_Spring 注解
- Spring学习(1)——IoC部分
- Vue笔记(11) vue-router
- vue.js 渲染函数_Vue.js的不可渲染且可扩展的RTF编辑器[通俗易懂]
- CVE-2022-22947:Spring Cloud Gateway远程代码执行漏洞
- 在网页文档中引入Vue.js的方法有哪些?_vue直接引入js文件没有用
- Vue.js – 引入外部 JS 文件
- Spring Boot 项目鉴权的 4 种方式
- vue入门篇之Vue.js 组件
- 如何在非Spring容器管理的类中注入/获取 Spring容器中的 Bean?
- Spring Boot 3 将于 2022 年 11 月发布,延迟了对 Java 模块系统的支持
- Spring Boot的RESTful API开发(二)
- 【Vue-Spring跨域Bug已解决】has been blocked by CORS policy: The value of the······
- Spring Data MongoDB 级联操作详解数据库
- Spring Boot2.0之 整合XXL-Job详解编程语言
- spring使用Spring整合Redis和Jedis构建高性能应用(redisjedis与)
- CVE-2018-1270:spring-messaging远程代码执行漏洞分析预警
- 优雅的Vue请求Redis驱动的高性能服务(vue请求redis)
- Vue快速连接Redis实现数据存储(vue 直连redis)
- Vue实时监测Redis变化(vue监控redis变化)
- 使用Vue和Redis创建完美的后台应用(vue redis后台)
- Oracle Vue考场助力企业数据库技术突破(oracle vue考场)
- java中spring定时任务实现代码