We have a requirement to embed grafana dashboards within our web application. We have tomcat as webserver and our application is deployed as a war file. We do not have any proxy services such as ngnix or apache in front of tomcat web server.
After researching online, I found that we can use apa-webcontent2-reverse-proxy and add reverse proxy servlet directly to tomcat and provide configuration to redirect traffic to grafana. I have added the required libraries and configured reverse proxy servlet inside my web.xml.
Here is the snippet of my web.xml configuration.
<servlet>
<servlet-name>ReverseProxyServlet</servlet-name>
<servlet-class>org.apache.portals.applications.webcontent2.proxy.servlet.SimpleReverseProxyServlet</servlet-class>
<init-param>
<param-name>mappings</param-name>
<param-value>
/WEB-INF/rproxy-mappings.yaml
</param-value>
</init-param>
<init-param>
<param-name>ssl-hostname-verifier</param-name>
<param-value>ALLOW_ALL_HOSTNAME_VERIFIER</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ReverseProxyServlet</servlet-name>
<url-pattern>/rproxyservlet/*</url-pattern>
</servlet-mapping>
I have also added configuration inside rproxy-mappings.yaml file to forward requests ending with /grafana to my grafana instance.
--- !regex
localPattern: ^.*/public/(.*)$
remoteReplace: http://localhost:3000/public/$1
remotePattern: ^/public/build/(.*)$
localReplace: http://localhost:3000/public/build/$1
contentRewriters:
text/html: !!org.apache.portals.applications.webcontent2.proxy.rewriter.DefaultReverseProxyTextLineContentRewriter []
--- !regex
localPattern: ^.*/avatar/(.*)$
remoteReplace: http://localhost:3000/avatar/$1
remotePattern: ^/public/build/(.*)$
localReplace: http://localhost:3000/public/build/$1
contentRewriters:
text/html: !!org.apache.portals.applications.webcontent2.proxy.rewriter.DefaultReverseProxyTextLineContentRewriter []
--- !regex
localPattern: ^.*/api/live/ws$
remoteReplace: ws://localhost:3000/api/live/ws
remotePattern: ^/public/build/(.*)$
localReplace: http://localhost:3000/public/build/$1
contentRewriters:
text/html: !!org.apache.portals.applications.webcontent2.proxy.rewriter.DefaultReverseProxyTextLineContentRewriter []
--- !simple
local: /grafana/
remote: http://localhost:3000/
contentRewriters:
text/html: !!org.apache.portals.applications.webcontent2.proxy.rewriter.DefaultReverseProxyTextLineContentRewriter []
When I try to access the dashboard url through the reverse proxy servlet, I see page not found inside grafana
Not sure what configuration is missing. Any pointers on how to solve this ? Did anyone try running grafana behind apa-webcontent2-reverse-proxy ? Any help is greatly appreciated. Thank you.