0

I'm having a nginx server and a domain, example.com. Each customer has his own subdomain, like wsb.example.com etc. Their content changes via PHP, but all subdomains get redirected to the same folder on the web server.

The only problem I'm having, is with accessing the domain without https. https://whatever.example.com/ works, but whatever.example.com redirects me to https://*.example.com/

What am I doing wrong?

server {
        listen *:80;
        listen *:443 ssl;
        server_name *.alterament.de;

        index index.php;
        root /var/www/webapp.alterament.de/public;

        ssl_certificate         ssl/alterament.de.crt;
        ssl_certificate_key     ssl/alterament.de.key;

        if ($ssl_protocol = "") {
                rewrite ^/(.*) https://$server_name/$1 permanent;
        }

        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }

        location /resources {
                root /var/www/webapp.alterament.de;
        }
}
mstoldt
  • 1
  • 1

2 Answers2

1

You used $server_name in your redirect, which causes the content of the server_name directive to be used. This is not what you want.

Instead, you should replace it with $host.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
0

This configuration checks if the protocol is not https and force to use https:

if ($ssl_protocol = "") {
       rewrite ^/(.*) https://$server_name/$1 permanent;
}

Try to comment out the whole block and restart nginx

Guido Vaccarella
  • 1,418
  • 14
  • 13
  • That works, but the rewrite makes sense so is there a way to add a https without changing the domain to *.example.com? – mstoldt Jul 23 '15 at 13:30