Tweak Application behaviors with NSX ALB
Tags: avi, nsxalb, vmware
Published: 2022-11-06 19:22:59

---
title: Tweak Application behaviors with NSX ALB
published: true
date: 2022-11-06 19:19:00 UTC
tags: Avi,NSXALB,VMWare
canonical_url: https://blog.engyak.co/2022/11/tweak-application-behaviors-with-nsx-alb.html
---

Not every application is designed to leverage a load balancer.

Early load balancing solutions capitalized on this fact - which may seem odd. The solution to the supportability issue creates new opportunity; we'll look at some examples here. Adjusting application behaviors quickly becomes a powerful tool when enhancing customer experience.

This was the story before digital transformation patterns began to emerge, at least. Business now prefer to use Commercial Off-The-Shelf (COTS) software and Content Management System (CMS) systems instead of writing raw code or web frameworks. This means that the software our SWEs are using is **considerably less "tunable" than it used to be** , and that the business line expects victory when adopting newer software.

They aren't wrong, the advantage at the other end of this transition is more maintainable software. It's important to be accommodating and compassionate when helping web developers improve their app - they didn't write it, and it's a new approach for them too.

Knowledge of how HTTP works is valuable here. For this exercise, I'm going to proxy Jenkins - it's not designed for a load balancer and is open source.

**It's really important to standardize behavior with load balancers**. Any profile or rule **should** be captured either in source control or a manager of managers. I prefer **both** , because tools like Git Pull Request provide a valuable place for peer review and seeking input on standards. It's good to have standards, it's better all qualified engineers agree on the standard (and there's a way to version/release new ones!)

We'll be using the following profiles for this application as a starting point:

- [http-profile-Jenkins-v1.0.0](https://github.com/ngschmidt/python-restify/blob/main/nsx-alb/profiles/http/http-profile-jenkins-v1.0.0.json)

  - This profile looks comprehensive - Avi Vantage stores all variables **explicitly** when anything is customized. Here are the highlights:

    - **Enable HSTS:** (Not required, I just like it. NSX ALB/Avi doesn't configure a separate service for port 80, so this ensures we don't run cleartext traffic.
    - **Reset HTTP on HTTPS connections** : This is an Avi oddity - by default, HTTPS services will return an HTTP 400 series code instead of resetting the connection. I don't like giving out thumbprint data on a given port when it asks for illegal output.
    - **X-Forwarded-For** : Avi will include an HTTP Header with this label and the client's IP address. This allows a web engineer to configure logging with the real address in 1-arm deployment scenarios
- [clienttls-v1.0.0](https://github.com/ngschmidt/python-restify/blob/main/nsx-alb/profiles/tls/clienttls-v1.0.0.json)

  - This client TLS profile is short because we can be strict on security.

    - Include a **short** acceptable cipher suite/cipher list, and enforce forward secrecy
    - Only support TLS 1.2 and 1.3
    - Prefer server cipher ordering (enforce good cryptography)

We've already covered significant ground in terms of standardization and user experience here. Many web apps don't plan to implement user-friendly TLS, for example, and benefit from NSX ALB/Avi in front of their web tier, acting as a security guard until the client successfully negotiates TLS and navigates to the appropriate port. **Many offerings also layer WAF, DDoS protection** into their products for this very reason.

Let's configure a basic virtual service:

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpmMA6BJQiYV96jqKCQuwcW-W5LMPLZ9GgobPnucuAfLV7Nj3n1KxyGBVRhUdoHrjk2WacD5a0-xRldMjWCRLd_TyAVNE2cWa3QjwOYqMs68FSWECvEEvoB-qLQ9CkgypcyyHZ8Srx903jQl_V_EulK7-hmA_ueafxObnq73d2GvmocQji3C3PnNjH/w883-h684/2022-11-06%2009_30_51-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpmMA6BJQiYV96jqKCQuwcW-W5LMPLZ9GgobPnucuAfLV7Nj3n1KxyGBVRhUdoHrjk2WacD5a0-xRldMjWCRLd_TyAVNE2cWa3QjwOYqMs68FSWECvEEvoB-qLQ9CkgypcyyHZ8Srx903jQl_V_EulK7-hmA_ueafxObnq73d2GvmocQji3C3PnNjH/s1090/2022-11-06%2009_30_51-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)

This basic wizard will establish some acceptable defaults. Let's modify the virtual service and add our settings:

- Application Profile
- TLS Profile
- Certificate

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPF7aFr4seeKf6y9UHZGtJkh2TtcH1ZKsRJw_iTGODcTocfclMt3wo4CaGNhNQHULjP_oj5L1RWD_j3zwGFGwfCyuX2zUMW_qLPHOb8VNWzKIT-XDA7ofK3OHdS9GQZoZHefwZdPQytaEatWtChcUborvUcEDAk9CSLzLugk4YCUPMA3_9aO3R8uRY/w873-h859/2022-11-06%2009_31_28-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPF7aFr4seeKf6y9UHZGtJkh2TtcH1ZKsRJw_iTGODcTocfclMt3wo4CaGNhNQHULjP_oj5L1RWD_j3zwGFGwfCyuX2zUMW_qLPHOb8VNWzKIT-XDA7ofK3OHdS9GQZoZHefwZdPQytaEatWtChcUborvUcEDAk9CSLzLugk4YCUPMA3_9aO3R8uRY/s1086/2022-11-06%2009_31_28-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)

Let's also configure this service to listen on port 80.

**Note: Avi will forward unencrypted traffic to the pool, so some loss of privacy may occur if you don't configure the redirect rule under Profiles -> HTTP Request prior to saving!**

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTl3zkBBXm6L0z0EJxQQgPw3SqzazKYBu6BHgol2mzoONYGYQzI4VYvtZ9id8wwjsOpWt9h-RyCMdRJbc-iZPuuLKtL-MDiPqhAHxfV77Lbem_oOeGqfp7KKhwqlbXPbu8jAXNsCKJR-02SLNTp5J2-1JfL47LKEENVAZx3GofV0Rt2p-24VM1sVip/w400-h161/2022-11-06%2009_31_49-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTl3zkBBXm6L0z0EJxQQgPw3SqzazKYBu6BHgol2mzoONYGYQzI4VYvtZ9id8wwjsOpWt9h-RyCMdRJbc-iZPuuLKtL-MDiPqhAHxfV77Lbem_oOeGqfp7KKhwqlbXPbu8jAXNsCKJR-02SLNTp5J2-1JfL47LKEENVAZx3GofV0Rt2p-24VM1sVip/s537/2022-11-06%2009_31_49-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsCTqbhucbbDvWtyn_NeuwUlU3mZgWzFdvhJEtCltkrhdh47iLTJAxYZgLLx01Qzn354Ja7yKmH4GqvWlEalHVDbi6-s94jkDrndYPHDCySw2XNZBBNp2UsTec2dGYyzpxLSKhpok79XzZQb4FjHeGZe6XqTYI-vjPWlELgEhPEFDgKSocZ-2jdY0Q/w861-h546/2022-11-06%2009_33_09-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsCTqbhucbbDvWtyn_NeuwUlU3mZgWzFdvhJEtCltkrhdh47iLTJAxYZgLLx01Qzn354Ja7yKmH4GqvWlEalHVDbi6-s94jkDrndYPHDCySw2XNZBBNp2UsTec2dGYyzpxLSKhpok79XzZQb4FjHeGZe6XqTYI-vjPWlELgEhPEFDgKSocZ-2jdY0Q/s1084/2022-11-06%2009_33_09-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)

The new service should be healthy under **Application -> Dashboard:**

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEaPXGwGWhLPKABFKkeHczZP6hrp8OBbkUqSkUFyhS2OpPKE5Q4VN2bdkI9Vou5BgdKixmEKZ_VHzhlofHOtbyXd5bqcFkuwMkOvbwt7B9nCNS08j9W-kGCCGmg0Ei8hE0JufQUnXcylfKKKKd9hVEwG_DXNJqHhpMZYbCbVmiOVGqDc_-ZdOSipgL/s1600/2022-11-06%2009_34_38-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEaPXGwGWhLPKABFKkeHczZP6hrp8OBbkUqSkUFyhS2OpPKE5Q4VN2bdkI9Vou5BgdKixmEKZ_VHzhlofHOtbyXd5bqcFkuwMkOvbwt7B9nCNS08j9W-kGCCGmg0Ei8hE0JufQUnXcylfKKKKd9hVEwG_DXNJqHhpMZYbCbVmiOVGqDc_-ZdOSipgL/s220/2022-11-06%2009_34_38-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)

Let's try and use the app!

We encounter an error when clicking "Manage Jenkins":

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg98Dj3MEQMZlNiJJcAVdjYNDMg2ynht2tIrcCRmuMciSWdsYkn2Ixd0u7cnYPISDgwVp0ee2OPeveXL9ojzAugcXrRyXIaqNlN_e5uj_auDQ3wTh1GHsgpV81sT6EH9Iy_rbTYTHYUZQOZ3lT2iKr9Wj8Zp0xOg8bOG1z86nlj96jt8V04RwjKlIuO/w400-h29/2022-11-06%2009_45_19-Problem%20loading%20page%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg98Dj3MEQMZlNiJJcAVdjYNDMg2ynht2tIrcCRmuMciSWdsYkn2Ixd0u7cnYPISDgwVp0ee2OPeveXL9ojzAugcXrRyXIaqNlN_e5uj_auDQ3wTh1GHsgpV81sT6EH9Iy_rbTYTHYUZQOZ3lT2iKr9Wj8Zp0xOg8bOG1z86nlj96jt8V04RwjKlIuO/s369/2022-11-06%2009_45_19-Problem%20loading%20page%20%E2%80%94%20Mozilla%20Firefox.png)
  

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipi-3UNG3w1lVGO-wWtZ9Rjhovuk97ruvhc_iVpbxzoQuFXlEoe2q3rBY01uAPMtWUPEIWKMGOrx-3ZV5deOQ6tS5g1mwJymqAd65ZDtKyCVpplX7RIYeM4FheZ-Fpc8wRM-dFNfzVZjtKDxtPt34Ol0fZJfbXBqTm8G7C0Uo4CdHCUAUBJRK5DBeH/w640-h250/2022-11-06%2009_45_29-Problem%20loading%20page%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipi-3UNG3w1lVGO-wWtZ9Rjhovuk97ruvhc_iVpbxzoQuFXlEoe2q3rBY01uAPMtWUPEIWKMGOrx-3ZV5deOQ6tS5g1mwJymqAd65ZDtKyCVpplX7RIYeM4FheZ-Fpc8wRM-dFNfzVZjtKDxtPt34Ol0fZJfbXBqTm8G7C0Uo4CdHCUAUBJRK5DBeH/s843/2022-11-06%2009_45_29-Problem%20loading%20page%20%E2%80%94%20Mozilla%20Firefox.png)

This is the configured name of my Jenkins server - and it's no longer using the virtual server's name.

We encounter this issue commonly with CMS, and "hard linked" applications can prove difficult to resolve. There are two approaches to resolving this issue:

- Leverage redirects, either:

  - Rewriting any redirects that flow through the load balancer
  - Redirecting from port 8080 to the correct service
- Rewrite HTML as it streams through the load balancer

  - Avoid this if possible, it's computationally very costly and may not support production traffic levels. It's still useful while developing a new website, as it might be a quicker hypothesis test than a coded solution or a vendor request for change (RFC)

Before diving into a specific fix, it's quite easy to categorize the problem with Firefox. Press **F12** on your keyboard to bring up the developer view, and select the **Network** tab:

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmYdX-V8Ifr4mlxQs6spTIzA207knJnCGWAF8ssFDcCvrlhi0AvN8NEv6g2vqMno7JrEqusnP7n1KL-_f7cu6yZB1YXw2JvAHch04vNlZP-NWKqcptkm5JLReDEc9BSWdXlO5gv5MQ3P_w4a1F4283eHjFEd8D0mWViOD1GQ2qPySf30yrlEBae85Z/w400-h56/2022-11-06%2009_51_24-Manage%20Jenkins%20%5BJenkins%5D%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmYdX-V8Ifr4mlxQs6spTIzA207knJnCGWAF8ssFDcCvrlhi0AvN8NEv6g2vqMno7JrEqusnP7n1KL-_f7cu6yZB1YXw2JvAHch04vNlZP-NWKqcptkm5JLReDEc9BSWdXlO5gv5MQ3P_w4a1F4283eHjFEd8D0mWViOD1GQ2qPySf30yrlEBae85Z/s384/2022-11-06%2009_51_24-Manage%20Jenkins%20%5BJenkins%5D%20%E2%80%94%20Mozilla%20Firefox.png)

**Note: This is a big part of why web developers always think it's the network that broke their application.**

Click the link again, and you will see a play-by-play of the HTTP transactions executed complete the transaction:

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3GD3Pr6iOhWmO3YUCUu3_kbJOxgLixR7SVbkr_dirnLTBA4EJGid08-IcuxABUPFnTt_Ufpq51l8Mawh1FIiEPaKyTLllYdwh4Z80OB-p31aVSB0GDYJZ8VNxN6BJno2fMMDkNgOewYDK4k4qgqXUVsPgVfMcfhwHZSGMVyFZ84iRknyCx4shBAVh/w640-h130/2022-11-06%2009_53_17-Problem%20loading%20page%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3GD3Pr6iOhWmO3YUCUu3_kbJOxgLixR7SVbkr_dirnLTBA4EJGid08-IcuxABUPFnTt_Ufpq51l8Mawh1FIiEPaKyTLllYdwh4Z80OB-p31aVSB0GDYJZ8VNxN6BJno2fMMDkNgOewYDK4k4qgqXUVsPgVfMcfhwHZSGMVyFZ84iRknyCx4shBAVh/s664/2022-11-06%2009_53_17-Problem%20loading%20page%20%E2%80%94%20Mozilla%20Firefox.png)

That's a bingo. Jenkins is forwarding a non-relative HTTP 302 ( **also known as: The link is in another castle** HTTP code). Let's rewrite it with NSX ALB by creating an **HTTP Response Policy**. 

Here's a quick cheat sheet:

- HTTP Response policies let an engineer edit HTTP transactions (but not the body) from the server to the client
- HTTP Request policies let an engineer edit HTTP transactions (but not the body) from the client to the server

[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_FvvathJvvQL7A8MVGmlvNL6FU9ygo0E3OxnytPjYqhBNe7LpWfybynKff9KHvgVwBu9Mz7yB3q0gWEejguKN1cGZJbk8CfkFksSO0CSllFJnx1Gt3SFIa71miAs1YwC-cT4sNlx-RiwTWR0HgRINmYBrSkj7V6VcroFC24uutpe64_uP9YFiEx0w/w873-h465/2022-11-06%2009_58_09-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_FvvathJvvQL7A8MVGmlvNL6FU9ygo0E3OxnytPjYqhBNe7LpWfybynKff9KHvgVwBu9Mz7yB3q0gWEejguKN1cGZJbk8CfkFksSO0CSllFJnx1Gt3SFIa71miAs1YwC-cT4sNlx-RiwTWR0HgRINmYBrSkj7V6VcroFC24uutpe64_uP9YFiEx0w/s1072/2022-11-06%2009_58_09-NSX%20ALB%20%E2%80%94%20Mozilla%20Firefox.png)

The `Location` header in an HTTP transaction applies specifically to redirects (301,302) - and as such is easy for a load balancer to rewrite. In this case, it wasn't the HTML pages that had a bad link - the redirect chain `/manage->/manage/` was the culprit.

VMware NSX ALB (and any other self-respecting ADC) presents an infrastructure engineer with near unlimited power to ensure that an application is delivered correctly (even if there's a flaw in the product). Check out the Developer Screen's network tab (F12) in Firefox/Chrome on some common websites - you will find that many of them employ similar "fixer" tactics.