2016-10-14 32 views
0

有人可以幫我錯誤HTTP 405時使sesion開始使用負載均衡NGINX

我使用NGINX實現負載均衡,但是當我嘗試使用一些使用Spring的安全,用Java開發的Web應用程序的時候我嘗試登錄在其中一個應用程序中返回HTTP 405 - 請求方法'POST'不受支持。

enter image description here

我NGINX的conf文件是這樣的:

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令牌

enter image description here

+0

似乎Tomcat拋出異常,而不是NGINX拋出異常。哪個HTTP請求被髮送?它是GET還是POST?如果瀏覽器發送的請求是POST,那麼問題似乎與您的不支持POST方法的應用程序代碼(Spring-MVC?)有關。 –

回答

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; 
    } 

}