V
V
Vladimir Revyakin2016-07-06 12:21:24
Nginx
Vladimir Revyakin, 2016-07-06 12:21:24

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

3 answer(s)
P
Pavel, 2016-07-06
@jonimuesli

return 301 https://$server_name$request_uri;

A
Andrey Burov, 2016-07-06
@BuriK666

Redirect from HTTP to HTTPS NGINX?

H
hdhog, 2016-07-07
@serjius


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 question

Ask a Question

731 491 924 answers to any question