从javascript重定向后502 Bad Gateway

时间:2014-11-25 07:58:50

标签: java tomcat grails nginx https

我尝试使用https在我的应用程序中的某些页面使用

java 8 - grails 2.4.4 - tomcat 8 - nginx 1.7.7 - 用于测试的自签名SSL证书 - ubuntu 14.10 - 托管在Microsoft Azure VM上 -

问题是浏览器在https:

中重定向后显示502 Bad Gateway

enter image description here

在ajax调用之后,javascript会进行重定向。 正如你在图片中看到的那样,.done()就是调用。

enter image description here

如果好的话,ajax会打电话。但重定向产品出现此错误。我可以通过重新加载来更改重定向,它具有相同的效果。

enter image description here

我的配置

Grails配置:
1 - Grails Spring安全核心插件:https://github.com/grails-plugins/grails-spring-security-core

    grails {
        plugin {
            springsecurity {
                auth.forceHttps = true
                secureChannel.useHeaderCheckChannelSecurity = true
                secureChannel {
                    secureHeaderName = 'X-Forwarded-Proto'
                    secureHeaderValue = 'http'
                    insecureHeaderName = 'X-Forwarded-Proto'
                    insecureHeaderValue = 'https'
                }
            }
        }
    }

2 - Grails Force SSL插件:https://github.com/bertramdev/grails-force-ssl 我在控制器上使用@SSLRequired来强制页面切换到https,它可以正常工作

Tomcat配置:

    <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="200000"
           redirectPort="8443"
            URIEncoding="UTF-8" 
            scheme="https"
            proxyName="myapp.cloudapp.net"
            proxyPort="443" />


    <Connector port="8443"
      protocol="org.apache.coyote.http11.Http11Nio2Protocol"
      maxThreads="200" scheme="https" secure="true" 
      SSLEngine="on" 
      SSLCertificateFile="/cert/server.crt" 
      SSLCertificateKeyFile="/cert/server.key" 
      SSLPassword="starwars" 
      clientAuth="false" sslProtocol="TLS"/>


    <Valve className="org.apache.catalina.valves.RemoteIpValve"
       remoteIpHeader="x-forwarded-for"
       remoteIpProxiesHeader="x-forwarded-by"
       protocolHeader="x-forwarded-proto" />

Nginx配置:

我添加了很多指令并增加了测试值

server {
  listen          80;
  server_name     myapp.cloudapp.net;


  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://localhost:8080/;

        add_header 'Access-Control-Allow-Origin' '*';
        proxy_redirect    off;
        proxy_send_timeout 6000;

  }
}

server {
    listen 443 ssl;
    server_name myapp.cloudapp.net;

    ssl on;
    ssl_certificate         /cert/server.crt;
    ssl_certificate_key     /cert/server.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;

    client_max_body_size                            32M;
    client_body_buffer_size                         4M;
    proxy_connect_timeout                           10000;
    proxy_send_timeout                              10000;
    proxy_read_timeout                              10000;
    proxy_buffers                                   32 4M;

    access_log /var/log/nginx/nginx.vhost.access.log;
    error_log /var/log/nginx/nginx.vhost.error.log;

    location / {
        set $tempRequest $request;
        if ($tempRequest ~ (.*)j_password=[^&]*(.*)) {
            # Mask spring authentication password param.
            # Set a temporary request parameter for loggin
            set $tempRequest $1j_password=****$2;
        }

        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto https;
        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_set_header X-Url-Scheme $scheme;
        proxy_redirect off;

        proxy_connect_timeout      240;
        proxy_send_timeout         240;
        proxy_read_timeout         240;

        proxy_pass http://localhost:8443/;

        proxy_redirect http://$host https://$host;
    }

需要帮助 感谢

0 个答案:

没有答案