2012-06-14 45 views
0

我有Tomcat 6在路徑「be」上運行web應用程序。 Spring安全性用於登錄過程。登錄網址爲/console/login,登錄後重定向至/console/customer。我使用https爲login url和http爲customer URL。我沒有在任何spring配置文件中指定servlet路徑。所有工作正常,訪問/be/console/login後正確的重定向(至)收到。nginx代理添加servlet路徑

現在我想要一個代理。我配置Nginx轉發https://localhosthttps://<someip>:9443和http相同,從端口80轉發到端口9080.

問題是,Nginx正在返回無效的重定向到瀏覽器。相反它返回/be/be/console/customer。 Servlet路徑被添加到URL兩次。

那第二個'be'怎麼可能被刪除?

謝謝。

Nginx的配置:

server { 
    listen  443 ssl; 
    server_name localhost; 

    ssl     on;   
    ssl_certificate  C:\jc\\nginx\\tc\selfsigned.cer; 
    ssl_certificate_key C:\jc\\nginx\\tc\private.key; 

    ssl_session_timeout 5m; 

    ssl_protocols SSLv2 SSLv3 TLSv1; 
    ssl_ciphers HIGH:!aNULL:!MD5; 
    ssl_prefer_server_ciphers on; 

    location/{ 
      proxy_redirect   off; 
      proxy_pass    https://<some ip>:9443; 
      proxy_set_header  X-Real_IP $remote_addr; 
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header  Host $http_host; 
    } 

    location ~ /.+ { 
      proxy_redirect   off; 
      proxy_pass    https://<some ip>:9443; 
      proxy_set_header  X-Real-IP $remote_addr; 
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header  Host $http_host; 
    } 
} 
server { 
    listen  80; 
    server_name localhost; 

    access_log logs/access.log; 
    error_log logs/error.log; 

    location/{     
      proxy_redirect   off; 
      #server_name_in_redirect off; 
      proxy_pass    http://<some ip>:9080;    
      proxy_set_header  X-Real_IP $remote_addr; 
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header  Host $http_host; 
    } 

    location ~ /.+ { 
      proxy_redirect   off;     
      proxy_pass    http://<some ip>:9080; 
      proxy_set_header  X-Real-IP $remote_addr; 
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header  Host $http_host; 
    } 
} 

回答

0

此配置是工作在生產:

location /demo/ { 
    proxy_pass http://localhost:8080; 
    proxy_redirect  off; 

    proxy_set_header Host    $host; 
    proxy_set_header X-Real-IP  $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_pass_request_headers on; 

    client_max_body_size  10m; 
    client_body_buffer_size 128k; 

    proxy_connect_timeout  90; 
    proxy_send_timeout   90; 
    proxy_read_timeout   90; 

    proxy_buffer_size   4k; 
    proxy_buffers    4 32k; 
    proxy_busy_buffers_size 64k; 
    proxy_temp_file_write_size 64k; 
} 
+0

proxy_pass_request_headers是在默認情況下,其餘的(不同的特性參數的)只是性能相關的配置。所以這個問題要複雜得多。 – Dima