可以使用以下配置来反代匹配网站首页 index.html:

server {
    listen       80;
    server_name  example.com;

    location / {
        proxy_pass  http://backend;
        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;

        if ($request_uri = '/') {
            rewrite ^ /index.html break;
        }
    }
}

在上面的配置中,如果请求的 URI 是 /,则会将其重写为 /index.html,然后使用 proxy_pass 指令将请求转发到后端服务器。同时,通过设置 proxy_set_header 指令将 Host、X-Real-IP 和 X-Forwarded-For 头信息传递给后端服务器。

nginx 反代 匹配网站首页 indexhtml

原文地址: https://www.cveoy.top/t/topic/bG6H 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录