0

I have set up OSRM (Open source routing machine) with nginx. It works as it was supposed to. But, the problem is I can't make it work over ssl. I have set the ports 443, the site over nginx works with https, everything is fine, just the OSRM service or how do I call it, which is running on ubuntu machine, it does not work. The page when I access /location says:

400 Bad Request

The plain HTTP request was sent to HTTPS port

Here is my osrm.config file:

  upstream osrm {
  # commented out  server 0.0.0.0:5000;
    server 0.0.0.0:443;
}

server {
    listen 443;
    ssl on;
    ssl_certificate /my/valid/path/working;
    ssl_certificate_key /my/valid/path/working;
    server_name  my_server_sub_domain_is_here;

    location /mypath {
        proxy_pass http://osrm/;
        proxy_set_header Host $http_host;
    }
}

2 Answers2

1

With you current config the ssl part is terminated on the nginx server.

The following includes the extra configuration you need.

upstream osrm {
  # commented out  server 0.0.0.0:5000;
    server 0.0.0.0:443;
}

server {
    listen 443;
    ssl on;
    ssl_certificate /my/valid/path/working;
    ssl_certificate_key /my/valid/path/working;
    server_name  my_server_sub_domain_is_here;
    proxy_ssl  on;
    proxy_ssl_certificate     /etc/ssl/certs/backend.crt;
    proxy_ssl_certificate_key /etc/ssl/certs/backend.key;

location /mypath {
        proxy_pass http://osrm/;
        proxy_set_header Host $http_host;
    }

The parts I've added do the following

proxy_ssl Tells Nginx to send upstream traffic over ssl. docs
proxy_ssl_certificate Defines the certificate that should be used for the ssl traffic. docs
proxy_ssl_certificate_key Defines the private key for the certificate that is used. docs

Drifter104
  • 3,693
  • 2
  • 22
  • 39
  • @FestimCahani sorry my mistake, placed them at the location level, when they should have been at the server level – Drifter104 Sep 02 '16 at 13:47
  • I have putted it in nginx.conf, and doesnt give me errors while restarting nginx now, but still 400 bad request. Its like it never read the ssl files while defining proxy_ssl stuff – Festim Cahani Sep 02 '16 at 13:47
  • @FestimCahani try with my updated answer – Drifter104 Sep 02 '16 at 13:48
  • It still says not allowed, i think its not about the location or server level, about the config file level, this config file of mine is created side by side with default. Maybe I should put it in default configuration file. – Festim Cahani Sep 02 '16 at 13:53
  • @FestimCahani it sounds like something is wrong, because it should complain about it being in nginx.conf as they aren't allowed at that level. Can you post your nginx.conf too – Drifter104 Sep 02 '16 at 13:59
  • I just fixed it sir, by not adding proxy_ssl at all. the part: proxy_pass http://osrm/; replaced with: proxy_pass http://localhost:5000 (because the service was running on that port), and now it works. Thank you for your time – Festim Cahani Sep 02 '16 at 14:17
  • what you specify under mypath under location /mypath ? – dawncode Dec 02 '19 at 18:47
0

It was fixed. I just replaced:

 proxy_pass http://osrm/;

with:

proxy_pass localhost:5000;