Answer the question
In order to leave comments, you need to log in
How to redirect from http to https nginx?
virtual host config example
If I write in the site.io browser, then nothing opens, only if I write https://site.io with my hands , the site opens, I want site.io to be redirected to https://site.io
server {
# listen 80;
listen 443 ssl;
#listen 443 default_server;
#listen80;
server_name site.io
root /www/localhost/public/public;
index index.php;
access_log /var/log/nginx/default.access.log;
error_log /var/log/nginx/error.log;
location / {
#auth_basic "closed site";
#auth_basic_user_file /conf/htpasswd;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
Answer the question
In order to leave comments, you need to log in
server {
listen 80;
server_name wiki.example.ru;
return 301 https://$server_name$request_uri; # enforce https
}
server {
server_name wiki.example.ru;
server_name_in_redirect off;
listen 443 ssl http2;
access_log /var/log/nginx/access.wiki.log main;
keepalive_timeout 60;
large_client_header_buffers 4 16k;
location / {
root /var/www/example/wiki;
...
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question