Misc reverse proxy stuff
general issue you might face when usimg a reverse proxy
- false redirect
- use X-Forward-Headers
- may need custom redirect rules in proxy
- SameSite Cookie Attribute
- CORS issues
Terms Reverseproxy vs API Gateway
Reverseproxy handels the following things
- Load balancing policy
- SSL/TLS Termination
- SSL/TLS Encryption
- Name based virtual hosting
API Gateway can additionally handle the following things:
- API request validation
- Payload transformation
- rate limiting, quotas and throttling
- retry policy
reverse proxy in front of tomcat 9
By default tomcat 9 ignores x-forwarded header which can be a issue if you happen to have redirects in your app. To adress this you need to add org.apache.catalina.valves.RemoteIpValve to the
....
# in Server.Service.Engine.Host
<Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="x-forwarded-for" proxiesHeader="x-forwarded-by" protocolHeader="x-forwarded-proto" portHeader="x-forwarded-port" />
</Host>
</Engine>
</Service>
</Server>
``````
Here is a rudimetary ansible task to add this:
```yaml
name: Configure Tomcat to work behind a reverse proxy
lineinfile:
state: present
path: '{{ tomcat_home_dir }}/conf/server.xml'
regexp: 'className="org.apache.catalina.valves.RemoteIpValve"'
insertbefore: '</Host>'
# line breaks will break the regex and therefore the task
line: |
<Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="x-forwarded-for" proxiesHeader="x-forwarded-by" protocolHeader="x-forwarded-proto" portHeader="x-forwarded-port" />