Nginx 默认页面和根网络服务器指令

Nginx default page and root webserver directive

我有一个小型嵌入式 Linux 设备 运行 Nginx。我可以通过网络连接到它并在 Chrome 或 Firefox 中访问 PC 上的端点。我的默认页面包含指向 "loading.jpeg" 的 HTML 标记,它位于设备上的 /tmp/nginx/loading.jpeg。我可以在浏览器中输入:http://192.168.0.4/loading.jpeg 并查看我的图片。我还可以访问呈现 html 的端点并查看正确呈现的图像。

现在我希望能够在浏览器中访问根页面:http://192.168.0.4/ 并将其重定向到我的默认页面,该页面应该呈现 html 并显示图像。问题是,如果我为默认的“/”位置设置一个页面,我的指向 /tmp/nginx 的网络服务器根指令将不再有效。所以我显示了我的页面,但是找不到 loading.jpeg 图像。我试过将根请求重定向到我的默认页面,但这也破坏了网络服务器根。

如何为 Nginx 呈现默认网页,同时让我的网络服务器根目录可用?谢谢。

这不起作用(网络服务器根已损坏 - 尽管显示了预期的默认网页):

location / {

            default_type text/html;
            content_by_lua_file /sbin/http/serve_stream.lua;

            ## The streaming endpoint
            location /streaming {

                default_type text/html;
                content_by_lua_file /sbin/http/serve_stream.lua;

            }

这是我当前的 nginx.conf,没有重定向:

## Setup server to handle URI requests
server {

    # Setup the root
    root /tmp/nginx;

    ## Port
    listen       80; ## Default HTTP

    ## Android phones from Ice Cream Sandwich will try and get a response from
    server_name
            clients3.google.com
            clients.l.google.com
            connectivitycheck.android.com
            apple.com
            captive.apple.com;

    ## We want to allow POSTing URI's with filenames with extensions in them
    ## and nginx does not have a "NOT MATCH" location rule - so we catch all
    ## and then selectively disable ones we don't want and proxy pass the rest
    location / {

        # For Android - Captive Portal
        location /generate_204 {
            return 204;
        }

        # For iOS - CaptivePortal
        if ($http_user_agent ~* (CaptiveNetworkSupport) ) {
            return 200;
        }

        ## Raw WebSocket
        location /ws {

            lua_socket_log_errors off;
            lua_check_client_abort on;

            default_type text/html;
                content_by_lua_file /sbin/http/websocket.lua;

        }

        ## The streaming endpoint
        location /streaming {

            default_type text/html;
            content_by_lua_file /sbin/http/serve_stream.lua;

        }

        ## We can have file extensions in POSTing of /blahendpoints for filesystem
        ## control HTTP commands
        location ~ "\.(txt|bin)$" {

            ...

        }

    }

}

有多种解决方案。与 rewrite ... last 完全匹配的 location 块非常有效:

location = / {
    rewrite ^ /some.html last;
}

有关更多信息,请参阅 this document