Sam__
Sam__

Reputation: 31

nginx config still serving default home page after root has been set

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
server{
    server_name sample.com;
    listen 80;
    location = / {
        root /root_path;
        index index.html;
    }

    location / {
        # root /root_path;
        # index index.html;

        # proxy_pass http://127.0.0.1:5200;
        # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # proxy_set_header Host $host;  # pass the host header -                                     http://wiki.nginx.org/HttpProxyModule#proxy_pass

        # proxy_http_version 1.1;  # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version

        # WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
        # proxy_set_header Upgrade $http_upgrade;
        # proxy_set_header Connection $connection_upgrade;
    }
}

This is only config file in "/etc/nginx/site-enable", but still its load nginx default page. How is this possible? If default root is not defined within server block but only within location blocks does root defaults to nginx default root directory?

Upvotes: 2

Views: 720

Answers (1)

Sam__
Sam__

Reputation: 31

I found issue and solution for my question.

"It should be noted that using an index file causes an internal redirect, and the request can be processed in a different location. For example, with the following configuration:

location = / {
    index index.html;
}

location / {
    ...
}

a “/” request will actually be processed in the second location as “/index.html”. "

I Quote this from

> http://nginx.org/en/docs/http/ngx_http_index_module.html

In my case,i'm requesting to load index.html in first location block.

location = / { }

but nginx redirect and catch it from second location block.

location / { } 

but index.html file is commented there. so it'll load the default nginx page.

Upvotes: 1

Related Questions