做那种网站受欢迎免费企业网站建设哪家

当前位置: 首页 > news >正文

做那种网站受欢迎,免费企业网站建设哪家,c 购物网站开发流程,wordpress 免签约支付项目中反向代理 集成第三方的服务接口或web监控界面#xff0c;并实现与自身项目相结合的鉴权方法 依赖 smiley-http-proxy-servlet GitHub链接 2.0 版开始#xff0c;代理切换到jakarta servlet-api!–HTTP 代理 Servlet–dependencygroupIdorg.mit… 项目中反向代理 集成第三方的服务接口或web监控界面并实现与自身项目相结合的鉴权方法 依赖 smiley-http-proxy-servlet GitHub链接 2.0 版开始代理切换到jakarta servlet-api!–HTTP 代理 Servlet–dependencygroupIdorg.mitre.dsmiley.httpproxy/groupIdartifactIdsmiley-http-proxy-servlet/artifactIdversion2.0/version/dependencyjavax servlet-api 请选择 dependencygroupIdorg.mitre.dsmiley.httpproxy/groupIdartifactIdsmiley-http-proxy-servlet/artifactIdversion\({smiley-http-proxy-servlet.version}/versionclassifierjavax/classifier /dependency仅仅是接口代理默认官网示例使用即可参考第二个接口代理。 如果是完整的web监控服务 会出现 静态资源 因路径 加载错误。 以Nginx 以代理Grafana监控平台为例解决静态资源加载失败、及websocket连接问题 import org.mitre.dsmiley.httpproxy.ProxyServlet; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.filter.HiddenHttpMethodFilter;/*** 本地代理服务** author Smile*/ Configuration public class ProxyServletConfig {/*** 代理Grafana 监控平台*/ Beanpublic ServletRegistrationBeanProxyServlet servletRegistrationBean() {ServletRegistrationBeanProxyServlet servletRegistrationBean new ServletRegistrationBean(new ProxyServlet(), /grafana/*);servletRegistrationBean.addInitParameter(ProxyServlet.P_TARGET_URI, http://127.0.0.1:9999);servletRegistrationBean.addInitParameter(ProxyServlet.P_LOG, true); // 自动处理重定向servletRegistrationBean.addInitParameter(ProxyServlet.P_HANDLEREDIRECTS, false); // 保持 COOKIES 不变servletRegistrationBean.addInitParameter(ProxyServlet.P_PRESERVECOOKIES, true); // Set-Cookie 服务器响应标头中保持 cookie 路径不变servletRegistrationBean.addInitParameter(ProxyServlet.P_PRESERVECOOKIEPATH, true); // 保持 HOST 参数不变servletRegistrationBean.addInitParameter(ProxyServlet.P_PRESERVEHOST, true);return servletRegistrationBean;}/***接口代理*/Beanpublic ServletRegistrationBeanProxyServlet servletRegistration() {ServletRegistrationBeanProxyServlet servletRegistrationBean new ServletRegistrationBean(new ProxyServlet(), /one/*,/two/*,three/*);servletRegistrationBean.addInitParameter(ProxyServlet.P_TARGET_URI, http://localhost:8001/api);servletRegistrationBean.addInitParameter(ProxyServlet.P_LOG, true);return servletRegistrationBean;}/*** 禁用springboot 自带的 HiddenHttpMethodFilter 防止post提交的form数据流被提前消费* p* fix springboot中使用proxyservlet的 bug.* a hrefhttps://github.com/mitre/HTTP-Proxy-Servlet/issues/83bugs/a* a hrefhttps://stackoverflow.com/questions/8522568/why-is-httpservletrequest-inputstream-emptybugs/a** return */Beanpublic FilterRegistrationBeanHiddenHttpMethodFilter disableHiddenHttpMethodFilter() {FilterRegistrationBeanHiddenHttpMethodFilter registrationBean new FilterRegistrationBean();registrationBean.setFilter(new HiddenHttpMethodFilter());registrationBean.setEnabled(false); // 禁用过滤器return registrationBean;} } 直接访问grafana代理 springboot项目端口8088报错静态资源 路径不正确 导致加载失败 解决思路 springboot 代理的/grafana/* 到 http://127.0.0.1:9999 静态资源的访问失败 404或 错误的返回html首页是因为路径不符合此规则导致代理是失败 proxy_pass http://127.0.0.1:8088/grafana//; 由nginx代理到 // 则问题解决 使 /grafana/* 代理规则生效 其他访问的服务调用 nginx的这个代理 nginx配置参考 server {listen 8889;server_name localhost;# grafana websocket地址代理location /api/live/ws {proxy_http_version 1.1;proxy_set_header Upgrade \)http_upgrade;proxy_set_header Connection Upgrade;proxy_set_header X-real-ip \(remote_addr;proxy_set_header X-Forwarded-For \)remote_addr;proxy_pass http://127.0.0.1:9999;}location / {#add_header Access-Control-Allow-Origin ;add_header Access-Control-Max-Age 1728000;add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;add_header Access-Control-Allow-Headers satoken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type;add_header Access-Control-Allow-Origin \(http_origin;client_max_body_size 10m;if (\)request_method OPTIONS) {return 204;}# grafana支持配置apikey 免登录访问set \(auth Bearer eyJrIjoiN1pKYlk5akFDZWNoMlVSUEN1YllXdm0yd2VYN2RzZFIiLCJuIjoiYWRtaW5rZXkiLCJpZCI6MX0;# apiKey设置到header grafana免密访问proxy_set_header Authorization \)auth;proxy_pass http://127.0.0.1:8088/grafana//;proxy_set_header Host \(host;proxy_set_header X-Real-IP \)remote_addr;proxy_set_header X-Forwarded-For \(proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto \)scheme;proxy_connect_timeout 600;proxy_read_timeout 600;}}完美解决问题~~ 再看后端 日志 代理已正常
更安全的访问 只需要限制 原服务端口的放行仅本机可访问然后项目增加过滤器自行判断权限。 启动类添加ServletComponentScan扫描WebFilter增加 Filter import cn.dev33.satoken.stp.StpUtil; import jakarta.servlet.
; import jakarta.servlet.annotation.WebFilter; import jakarta.servlet.http.HttpServletResponse; import org.springframework.core.annotation.Order;import java.io.IOException; /*** 过滤器** author Smile/ Order(1) WebFilter(filterName piceaFilter, urlPatterns /grafana/) public class ProxyServletFilter implements Filter {Overridepublic void init(FilterConfig filterConfig) throws ServletException {Filter.super.init(filterConfig);}Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {//自行 实现条件判断即可if (StpUtil.isLogin()) {// 用户已登录继续执行过滤器链filterChain.doFilter(servletRequest, servletResponse);} else {// 用户未登录可以返回错误信息或重定向到登录页面// 例如返回 HTTP 401 未授权状态HttpServletResponse httpResponse (HttpServletResponse) servletResponse;httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);}}Overridepublic void destroy() {Filter.super.destroy();} } 未登录则
撒花收工~~ 附 grafana websocket需要修改custom.ini配置

allowed_origins is a comma-separated list of origins that can establish connection with Grafana Live.

If not set then origin will be matched over root_url. Supports wildcard symbol .allowed_origins

或 allowed_origins http://127.0.0.1:8889