0

I recently pass all my site to https here is a sample of cv site conf

server {
   listen 80;
   server_name cv.host.com;
   root /www/cv/app;
   index index.html index.htm index.php;
   access_log /www/log/cv/nginx-access.log;
   error_log /www/log/cv/nginx-error.log;
   location /
   {
       try_files $uri $uri/ =404;
   }
   location ~ \.php$
   {
      include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
   }
   listen 443 ssl;
   ssl_certificate /etc/letsencrypt/live/cv.host.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/cv.host.com/privkey.pem;
   include /etc/letsencrypt/options-ssl-nginx.conf;
   ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
   if ($scheme != "https") {
       return 301 https://$host$request_uri;
   } # managed by Certbot
}

But when i try to open http://cv.host.com my browser got redirected to https://host.com au lieu de https://cv.host.com

Ngninx seem to cal my default conf which is

server {
    listen  80 default_server;
    server_name _;    
    root /www/default/app;
    index index.html index.htm index.php;    
    access_log /www/log/default/nginx-access.log;
    error_log /www/log/default/nginx-error.log;    
    location /
    {
        try_files $uri $uri/ =404;
    }    
    location ~ \.php$
    {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }    
    listen 443 ssl default_server;
    ssl_certificate /etc/letsencrypt/live/host.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/host.com/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;    
    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

So when i ask http://cv.host.com i don't get the good site in https... is my config wrong? Any other way to redirect all to https?

1 Answer 1

-1

You can't put two vhosts on the same IP for ssl unless its using the same SSL cert.

This is due to how ssl works.. nginx doesn't know anything about the host header until it decrypts the stream. So when it connects at first it is hitting your default entry.

8
  • how i'm supposed to do then? becausereturn 301 cv.host.com$request_uri didn't work either
    – Jebik
    Nov 15, 2017 at 12:57
  • are you behind and load balancer?
    – Mike
    Nov 15, 2017 at 12:59
  • nop it's a little dedicated server every sub.host.com is a cname to host.com in my DNS and all I have to get the good site is nginx and my vhost
    – Jebik
    Nov 15, 2017 at 13:01
  • I woud have one server block just for port 80 that redirects everything to 443 and then break out your https server blocks
    – Mike
    Nov 15, 2017 at 13:01
  • to be fair i'm a noob and i had a server on 80 and use certbot to manage my config. it's certbot that generate config like this. with the redirect. so you think my server on 80 must only return to 443 ? and all the content must be in a server for 443? Can i have one config file? or must i seperate two server in two file?
    – Jebik
    Nov 15, 2017 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .