0

I have an azure kubernestes cluster where I am using applcation gateway in the front. the pod is serving an static index.html page. but somehow when I click on our website to the service, it is creating a post method and browser is throwing

"nginx 405 not allowed" error. but when I go to the address bar and just hit enter from the keyboard, it brings the content. but when I hit enter, in the broswer developer view, it shows the GET method. is there anyway to make it GET Method instead of POSt method sent to the ingress controller?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    appgw.ingress.kubernetes.io/appgw-ssl-certificate: cert
    kubernetes.io/ingress.class: azure/application-gateway
  creationTimestamp: "2022-08-01T11:43:56Z"
  generation: 11
  labels:
    app.kubernetes.io/instance: xxx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: xxx
    helm.sh/chart: XXXX-0.0.1-SNAPSHOT
  name: XXXX-ingress
  namespace: xxx
  resourceVersion: "xxx"
  uid: xxxx
spec:
  rules:
  - host: manuals.dat.de
    http:
      paths:
      - backend:
          service:
            name: xxx-svc
            port:
              number: 80
        path: /
        pathType: Prefix
status:
  loadBalancer:
    ingress: 
      - ip: xx.xx.xx.xx
Vivek Jain
  • 71
  • 1
  • 11
  • are you rendering static content on POST request? you can set the 405 error to 200 or set proxy t set post to get if that's the case. – Harsh Manvar Aug 10 '22 at 14:14

1 Answers1

0

This 405 Not Allowed through POST method error may be caused by entering an invalid URL or web servers will disallow access to improper URLs due to correct headers not found according to CSP (Content Security Policy).

You can configure the following in your nginx.conf to ensure that the error page 405 is redirected to 200 code URI page: -

server {
    listen       80;
    server_name  test.com;
 location / {
        root   /my/root; 
        index  index.html index.htm;
     }
    error_page  405     =200 $uri;
   # ...
}

Orelse based on similar threads as mentioned below wherein explained by akazakou, the Nginx’s default configuration forbids routing requests to static files. An error is produced when Nginx receives a POST request to the content of a static file.

Thus, creating an upstream server where your request will be forwarded if you intend to process POST requests through your own backend implementation will also help in mitigating the error faced.

upstream node_server {
    server 127.0.0.1:3030;
    keepalive 10;
}

server {
    server_name example.com;
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://node_server/;
      proxy_redirect off;
    }
}

Reference: POST request not allowed - 405 Not Allowed - nginx, even with headers included by Baskar

Imran
  • 3,875
  • 2
  • 3
  • 12