R
R
Rigorbb2017-01-23 10:47:58
Nginx
Rigorbb, 2017-01-23 10:47:58

How to set up the nginx config if there is one https and several http sites on the server?

The server has one site with https. This is the config for it:

server {
    listen       443;
    server_name  domen.ru;

...

server {
    listen 80;
    server_name www.domen.ru domen.ru;
    return 301 https://domen.ru$request_uri;
}

server {
    listen 443;
    server_name www.domen.ru;
    return 301 https://domen.ru$request_uri;
}

And there are several regular sites available via http. The problem is that if you request these sites via https, then the https site will open, and without redirection, but as if on the current domain. How to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Chudnovsky, 2017-01-23
@Frankenstine

Since you have only one https site, it is the default one, i.e. processes requests to undescribed sites received by the server. Therefore, in the config of this site, make a redirect for https requests to "left" names to http.

D
Dmitry Miksir, 2017-01-23
@miksir

Issue a certificate for each domain of http sites (otherwise browsers will swear) and register the https configuration for each of these sites in nginx. If you want a redirect - a separate server block, if you just want to get these sites via https - add listen 443 ssl and keys to the old server block.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question