错误原因:

nginx在进行请求转发时默认会忽略请求头参数中的下划线,而后端鉴权时需要从请求头中获取access_token进行鉴权,被忽略后实际传给后端的请求头参数为accesstoken,导致后端验证权限时无法获取到token,所有的请求都会报403无权限访问

解决办法:

nginx提供了一个参数underscores_in_headers,其默认值为off,表示忽略请求头参数中的下划线

调整nginx.config,在http下添underscores_in_headers on;

#user  nobody;
worker_processes  1;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    underscores_in_headers on;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}