502 Bad Gateway after redirect with javascript
I am trying to use https for some pages in my application using
java 8 - grails 2.4.4 - tomcat 8 - nginx 1.7.7 - self signed SSL certificate for tests - ubuntu 14.10 - hosted on a Microsoft Azure VM -
The problem is the browser displays 502 Bad Gateway after being redirected to https:
After the ajax call, javascript does the redirect. As you can see in the picture, .done () is a call.
And the ajax call if it's good. But redirect the product to this error. I can change the redirect by reloading, it is the same effect.
My config
Grails config:
1 - Grails Spring Core Security Plugin: 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 plugin: https://github.com/bertramdev/grails-force-ssl I am using @SSLRequired on the controller to force the page to switch to https and it works
Tomcat config:
<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 config:
I have added many directives and increased values for tests
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;
}
Need help Thanks
source to share
No one has answered this question yet
Check out similar questions: