2017-05-03 68 views
1

我有一個運行Nginx的小型嵌入式Linux設備。我可以通過網絡連接到它,並通過Chrome或Firefox訪問PC上的端點。我的默認頁面包含一個指向「loading.jpeg」的HTML標記,該標記位於設備上/tmp/nginx/loading.jpeg處。我可以輸入瀏覽器:http://192.168.0.4/loading.jpeg並查看我的圖像。我也可以訪問呈現html的端點並正確顯示我的圖像。Nginx的默認頁面和根網絡服務器指令

現在我希望能夠在瀏覽器中訪問根頁面:http://192.168.0.4/,並將其重定向到默認頁面,該頁面應呈現html並顯示圖像。問題是,如果我爲默認的「/」位置設置頁面,我的webserver root指令指向/ tmp/nginx不再有效。所以我顯示了我的頁面,但找不到loading.jpeg圖像。我已經嘗試將根請求重定向到默認頁面,但是這也打破了Web服務器根目錄。

如何爲Nginx呈現默認網頁,同時讓我的web服務器根目錄得到遵守?謝謝。

這不起作用(Web服務器的根壞了 - 雖然顯示預期默認網頁):

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)$" { 

      ... 

     } 

    } 

} 

回答

1

有一個解決方案的數量。用rewrite ... last完全匹配location塊是相當有效率:

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

更多見this document