gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:40:07 25 4
gpt4 key购买 nike

我有一个运行 Nginx 的小型嵌入式 Linux 设备。我可以通过网络连接到它,并在 PC 的 Chrome 或 Firefox 中访问端点。我的默认页面包含一个指向“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 block 非常有效:

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

参见 this document了解更多。

关于linux - Nginx 默认页面和根网络服务器指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43762524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com