有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 502从javascript重定向后出现错误网关

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

爪哇8- grails 2.4.4- tomcat 8- nginx 1.7.7- 用于测试的自签名SSL证书- ubuntu 14.10- 托管在Microsoft Azure虚拟机上-

问题是浏览器在https重定向后显示502坏网关:

enter image description here

在ajax调用之后,javascript执行重定向。 如图所示。done()是一个调用

enter image description here

如果好的话,还有ajax调用。但重定向产品会出现此错误。我可以通过重新加载来改变重定向,效果相同

enter image description here

我的配置

Grails配置:
1-GrailsSpring安全核心插件: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强制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) 个答案