W
W
wwwkat20152020-06-20 11:44:37
Nginx
wwwkat2015, 2020-06-20 11:44:37

Nginx https redirect?

It is necessary to make a redirect from http to https, the standard options do not work, which we managed to find.
Nginx server, OC debian 9, ssl certificate installed.

File /etc/ngnix/ngnix.conf https://pastebin.com/TDQBWJHW
File /etc/nginx/conf.d/site1.conf https://pastebin.com/tnE38A5G

When adding the following code to the top of the /etc/ file nginx/conf.d/site1.conf an error occurs and the server crashes.
Of course, the domain is registered on its own, the code is below with the domain of the site from where it is copied.
server {
listen 80;
server_name linuxize.com www.linuxize.com;
return 301 https://linuxize.com$request_uri;
}

I understand that the problem is that the config is made in such a way that when a folder is created, a site is created automatically.
But how do I redirect a single site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wwwkat2015, 2020-06-20
@wwwkat2015

The solution was to add the code to the beginning of the file /etc/nginx/conf.d/site1.conf
Code, YOUR_IP to be replaced with your own, as well as the site domain:
server {
listen YOUR_IP:80;
server_name site.com;
rewrite ^ https://site$request_uri? permanent;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question