A
A
Alexey2020-07-30 20:43:11
Nginx
Alexey, 2020-07-30 20:43:11

How to set default page in nginx?

How to make it so that when you enter site.ru, the login.html page automatically opens?

Config:

server {
    listen 443 ssl;
    server_name site.ru;
    include acme;

    location / {
        proxy_pass                          http://localhost:5000;
        proxy_set_header  Host              $http_host;
        proxy_set_header  X-Real-IP         $remote_addr; 
        proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto $scheme;
        proxy_read_timeout                  900;
        client_max_body_size 2000M;
    }
    ssl_certificate /etc/nginx/ssl/site.ru.crt;
    ssl_certificate_key /etc/nginx/ssl/site.ru.key;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers  "RC4:HIGH:!aNULL:!MD5:!kEDH";
    add_header Strict-Transport-Security 'max-age=600';
}

server {
    listen 80;
    server_name site.ru;
    rewrite ^ https://site.ru$request_uri? permanent;
}


If I add to location:
index login.html;
try_files $uri $uri/login.html;


then I get:
*1 rewrite or internal redirection cycle while internally redirecting to "//login.html/login.html/login.html/login.html/login.htm
l/login.html/login.html/login.html/login.html/login.html/login.html"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton B, 2020-07-30
@bigton

And if just
index login.html;
try_files $uri $uri/;

D
dodo512, 2020-07-30
@dodo512

Just add rewrite to the desired address.

location / {
    rewrite ^/$ /login.html;
    proxy_pass                          http://localhost:5000;

A
Alexey, 2020-07-31
@alenov

Found the reason. I did not specify the trailing slash in the instructions, you need it like this:

proxy_pass                          http://localhost:5000/;

Everything worked.
Thanks to all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question