1

I'm having trouble configuring my nginx server as a reverse proxy for different locations under the same ip address, using SSL.

Here's my nginx config file:

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {

    listen 443 default_server;
    server_name example.com;

    ssl_certificate           /etc/ssl/private/app1.crt;
    ssl_certificate_key       /etc/ssl/private/app1.key;
    ssl_certificate           /etc/ssl/private/app2.crt;
    ssl_certificate_key       /etc/ssl/private/app2.key;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    #App1
    location ^~ / {

      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;

      proxy_pass          https://10.0.x.x/;
    }

    #App2
    location ^~ /subdomain{

      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;

      proxy_pass          https://10.0.x.x/;
    }    
}

The above code works for the first location 'https://example.com/', but it does not work for 'https://example.com/subdomain'.

Can anyone provide some guidance on how to do this properly?

laker02
  • 107
  • 1
  • 1
  • 6
  • "example.com/subdomain" is not a subdomain, "subdomain.example.com" is. – virullius May 04 '20 at 17:12
  • To cite from the answer to the other question: *"Regular expressions, __in the order they are defined in the configuration file__."*. Thus your `^~` will catch already everything since it is before the longer regex. You need to change the order in your configuration. – Steffen Ullrich May 04 '20 at 18:35
  • @SteffenUllrich thanks! so the ssl part is ok then? i can have multiple ssl certificates specified in the server directive with no problem? – laker02 May 05 '20 at 09:10
  • @DiogoCarou: Your actual problem has nothing to do with SSL. As for multiple certificates just read [the documentation](https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate): *"Since version 1.11.0, this directive can be specified multiple times to load certificates of different types, for example, RSA and ECDSA"*. As for having different certificates for different path - this is not possible. – Steffen Ullrich May 05 '20 at 13:47

0 Answers0