本文介绍: *4、跨服务调用报错解决(亲测有效)

一、报错原因提示nginx 解决 405 not allowed错误

        问题产生原因:因为这里请求静态文件采用的是post方法nginx是不允许post访问静态资源。题话外,试着post访问了下www.baidu.com发现页面也是报错,可以试着用get方式访问

二、解决方式(四种)

1、、将405错误指向成功
         静态server下的location加入 error_page 405 =200 $uri;(说白了就是强制将405错误用200代替了)

location / {
        root /usr/locai/nginx/html/kt;
        try_files $uri $uri/ /index.html;
        index index.html index.htm;
        error_page 405 =200  $request_uri;
    }

2、修改nginxsrc/http/modules/ngx_http_static_module.c文件

if (r->method & NGX_HTTP_POST) {
     return NGX_HTTP_NOT_ALLOWED;
}

    把这一段注释掉,重新编译,将make install编译生成nginx文件复制sbin重启nginx

3、允许nginxpost请求访问静态资源个人感觉是强制post请求get

upstream static_backend {
    server localhost:80;
}
 
server {
    listen 80;
    # ...
    error_page 405 =200 @405;
    location @405 {
        root /srv/http;
        proxy_method GET;
        proxy_pass http://static_backend;
    }
}

**4、跨服务调用报错解决(亲测有效)

    server {
        listen       8010;
        server_name  localhost;
        location / {
            root   /usr/local/system/efe/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
            error_page 405 =200 @405;
        location @405 {
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             #ip为后端服务地址
             proxy_pass http://ip+端口$request_uri ;
        }
   }

原文地址:https://blog.csdn.net/qq_53314126/article/details/132542172

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_37060.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注