1

I have posted a similar question in stackoverflow. But since this site is better suited for this question, I am reposting it here.I am trying to redirect all requests on port 80 to port 443 ie,redirecting http to https (ssl) using haproxy.I have already created the pem certification file by referring to this link http://fosshelp.blogspot.com/2016/11/how-to-create-pem-file-for-haproxy.html. I have made sure to Append PRIVATE KEY and CRT(self-signed certificate) to mydomain.pem.

mydomain.pem

-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAoYIHQUmzceqx7dJfMbEp67v8J9C9BgXChoT5yR6zh8cVkQNT
hkG7x0S2W1kEtARsin6q5nl23k7MuK4GURHGz1H6lm2p/bO6hepyrvWDYhNXhUFy
QJ2I2qlCfP+0Szbf1CZ74dOFod6LWggIgKbliSc++0y4RWfxPO/WJHiR5d7khZjL
yYfKXgcV72yCUQJB/axNqUzgq+VA+NjXG4o192J6wHWVbDtSnC05OfVncxD27f+Q
Nbb00pBiMssET3ZBXwHu6mApf4OtfmQlxHKiKGVscnP9M1mc6eJLBVhuXEyLijfS
dWP2M9XZ2NNYrKDr1GMZcnTYVixhJrroPS1o3QIDAQABAoIBAArUFvxvnpJis+9I
DY3dXPwrLGrW+fVvaW1vePfdERhnZrDEUlNMEPT5TGivfTs8mLJob7joJ+obymoP
cOj6kiPQUUbIr38ND9Jut6W3XEm1Fkce7jQa29QdSRHsawAn+7XTprarYehKbXlp
1HgbuIQLl5Ntv2UX5Pq68dacJtwMjG1/2CffgOYqrbC3XxXxmLbT/iW2mTP/dhQo
SBVc6YGtY4jxz05D20gNhrwE1fz0rUion9SXNbBo+6i/NvuLjGNKqEBwMu9Mu5Ea
+0WoK0M/xhecLNTN/PEIGcs3ZfKfjGyQRHW/wJOwDjIK8clC36XyoNE5kfy5cW0C
Nr8LOtkCgYEAzJTEAZDf6m1Z4mO2vtQXJFVcrRsifG6bUiJCJp2uP9nCNNalet1V
/bzXNwE/8Ww4+fZQbuZOrAgurjyt0MNXdohD32/HWjr357rGa8o6f4kNjLrUwKqW
9CfMF0W48z6acQBtPrpRzoq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Z2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAoYIHQUmzceqx7dJfMbEp67v8J9C9BgXChoT5yR6zh8cVkQNT
hkG7x0S2W1kEtARsin6q5nl23k7MuK4GURHGz1H6lm2p/bO6hepyrvWDYhNXhUFy
QJ2I2qlCfP+0Szbf1CZ74dOFod6LWggIgKbliSc++0y4RWfxPO/WJHiR5d7khZjL
yYfKXgcV72yCUQJB/axNqUzgq+VA+NjXG4o192J6wHWVbDtSnC05OfVncxD27f+Q
Nbb00pBiMssET3ZBXwHu6mApf4OtfmQlxHKiKGVscnP9M1mc6eJLBVhuXEyLijfS
dWP2M9XZ2NNYrKDr1GMZcnTYVixhJrroPS1o3QIDAQABMA0GCSqGSIb3DQEBCwUA
A4IBAQAiVhxY9hBSIk3J8vppghyRBdjEEbxaefrmyXNkffP5rw9mVFWdDQAaXbyf
2sfP+XnXQtPUK5CqlifmQeO7Wf7I0Kfdn6KGYdBNHTj9fRRT28hJoloah5qlhv0r
ZNilT5xHS5F4E4IFkmctPKdGiSA5Ex0jaOYCV5sCFgNcR2xKTzgkD/6aWi8ObkxL
2xhtcvs67n2YqHFWcexPm8kFP/6MOG/6618Drdl6qZM93NPZ/1srQsLL5Jg769wx
+WKry946qYNaB7fk3SOfh5RMVnqbpXfVarjThd2aqicOTyL3VF4znRFeptFuC/gP
gZMEFH7XvQEsR0jMIKDzwS3F+/mj
-----END CERTIFICATE-----

haproxy.cfg


frontend http-in
    mode    http

    bind *:80
    bind *:443 ssl crt /etc/ssl/private/mydomain.pem
    http-request redirect scheme https code 301 if !{ ssl_fc }

    acl path-employeeList              path_beg -i /employeeList    
    use_backend employeeList-backend   if path-employeeList


backend employeeList-backend
    mode    http

    option  httplog
    option  forwardfor

    http-request set-path /

    server  appserver1 134.209.18.237:5000

Currently I can access my app at http://134.209.18.237/. But when I hit https://134.209.18.237/ I get 503 Service Unavailable No server is available to handle this request.Why is the redirection to https not working?Plz help

Is there anything wrong with my pem certificate file or my haproxy.cfg??Is the certificate file invalid??

0
0

You have no backend for /, only /employeeList so there's in fact no one to handle your request. 503 seems about right.

8
  • okay i changed /employeeList to / – Vignesh Swaminathan Sep 24 '19 at 6:58
  • i also removed http-request set-path / from the backend and now the app is succesfully getting redirected to https – Vignesh Swaminathan Sep 24 '19 at 6:59
  • but i am still confused? Can you explain me what was the problem with the previous configuration? – Vignesh Swaminathan Sep 24 '19 at 7:01
  • Take a request for /, look at your frontend configuration and tell me which backend you expect it will use. – Ginnungagap Sep 25 '19 at 21:10
  • okay lets say if /employeeList is an alias name for the portnumber 5000.How should i change my config if i want to access it at 134.209.18.237/employeeList ? – Vignesh Swaminathan Oct 14 '19 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.