PUT and POST getting 405 Method Not Allowed Error for Restful Web Services

后端 未结 6 2314
无人及你
无人及你 2020-12-09 18:32

I am trying to set up a simple Restful Web-Service which returns either JSON or XML according to the Accept header. I am using Spring, Maven and WebLogic Server. I took the

6条回答
  •  爱一瞬间的悲伤
    2020-12-09 19:12

    The problem is that POST method is forbidden for Nginx server's static files requests. Here is the workaround:

    # Pass 405 as 200 for requested address:
    
    server {
    listen       80;
    server_name  localhost;
    
    location / {
        root   html;
        index  index.html index.htm;
    }
    
    error_page  404     /404.html;
    error_page  403     /403.html;
    
    error_page  405     =200 $uri;
    }
    

    If using proxy:

    # If Nginx is like proxy for Apache:
    
    error_page 405 =200 @405; 
    
    location @405 { 
        root /htdocs; 
        proxy_pass http://localhost:8080; 
    }
    

    If using FastCGI:

    location ~\.php(.*) {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    include /etc/nginx/fastcgi_params;
    }
    

    Browsers usually use GET, so you can use online tools like ApiTester to test your requests.

    Source

    • http://translate.google.com/translate?hl=&sl=ru&tl=en&u=https%3A%2F%2Fruhighload.com%2F%D0%9E%D1%88%D0%B8%D0%B1%D0%BA%D0%B0%20nginx%20405%20not%20allowed

提交回复
热议问题