使用负载平衡NGINX启动会话时出现HTTP 405错误

时间:2016-10-14 18:28:26

标签: apache nginx spring-security proxy load-balancing

我使用NGINX实现Load Balancer,但是当我尝试使用Spring使用Java开发的一些webapp时,当我尝试登录其中一个应用程序时返回HTTP 405 - 不支持请求方法'POST'。 / p>

enter image description here

我的NGINX配置文件是这样的:

upstream myapp {
        server 172.16.80.49:8095;      
        server 172.16.53.31:8091;
    }

server {
        listen 80;

        location / {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://172.16.80.49:8092;
        }
        location /docentes {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://myapp;
        }
        location /gerentes {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://myapp;
        }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

我怎么能解决这个问题,我想应用程序的问题是csrf token

enter image description here

1 个答案:

答案 0 :(得分:0)

将我的cof改为:

upstream myapp {
        ip_hash;
        server 172.16.80.49:8095;      
        server 172.16.53.31:8091;
    }

server {
        listen 80;

        location / {
            proxy_pass http://172.16.80.49:8092;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  Host  $http_host;
        }
        location /docentes {
            proxy_pass http://myapp;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
        location /gerentes {
            proxy_pass http://myapp;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;      
        }
        location /dashboard {
            proxy_pass http://myapp;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;      
        }



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

}