Search code examples
apachenginxproxynginx-ingress

Create apache httpd forward proxy behind Nginx Ingress


I need to create a forward proxy on k8s (GKE) cluster. To do so, I created a simple httpd Deployment & A basic Nginx Ingress (With well-configured Service).

The forward proxy configuration:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
<VirtualHost *:80>
   HttpProtocolOptions Unsafe
   ErrorLog /var/log/test.log
   LogLevel debug
   CustomLog /var/log/test2.log combined
   ProxyPreserveHost On
   ProxyRequests On
   ProxyVia On
   ProxyStatus On
   ProxyTimeout 60
   AllowCONNECT 1080 443 8443 9443 8000-8900
   <Proxy "*">
      Allow from all
   </Proxy>
</VirtualHost>

The Nginx Ingress:


apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: stat-proxy
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: <somehost>
      http:
        paths:
          - path: /
            backend:
              serviceName: stats-service-proxy
              servicePort: 80

When running the command curl -L -x http://127.0.0.1:80 -I http://www.google.com from inside the pod, it works as expected and returns status code 200.

When running the command curl -x http://<ingress-nginx-hostname>:80 -I http://www.google.com , I'm getting error 404 from what looks like Ingress:

<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

Solution

  • Instead of using a Ingress, I changed the type of the Service to LoadBalancer