J
J
Justin Bieber2016-09-02 13:52:29
Nginx
Justin Bieber, 2016-09-02 13:52:29

How to enable redirect to https in nginx?

/etc/nginx/conf.d/site.ru.conf

server {
    listen   80;
    listen   443 ssl;
    server_name www.site.ru site.ru;
    ssl_certificate     /etc/letsencrypt/live/site.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem;

    access_log /var/www/site.ru/logs/nginx-access.log;
    error_log /var/www/site.ru/logs/nginx-error.log;

    location / {
  proxy_pass  http://127.0.0.1:81;
  include     /etc/nginx/proxy.conf;
    }

    location ~* \.(jpg|jpeg|gif|png|ico|css|bmp|swf|js)$ {
  root /var/www/site.ru/public;
      access_log off;
      expires 10d;
    }

    location /phpmyadmin {
         root /usr/share/;
         index index.php index.html index.htm;
         location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
      proxy_pass  http://127.0.0.1:81;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
         }

         location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
         }
    }

    location /phpMyAdmin {
         rewrite ^/* /phpmyadmin last;
    }

}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adgh, 2016-09-02
@JustinBieber

nginx redirect from http to https

J
Justin Bieber, 2016-09-02
@JustinBieber

solution
server {
listen 80;
server_name iiiypuk.me www.iiiypuk.me;
rewrite ^(.*) https://$server_name$1 permanent;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question