使用 nginx 提供登录页面。无法让“/”工作,而其他 URL 工作正常

使用 nginx 提供登录页面。无法让“/”工作,而其他 URL 工作正常

我正在尝试为我的网站设置一个登录页面(例如 example.com),并且我想在有人在浏览器中输入“example.com”时将我自己的 html 作为要加载的页面。我使用 nginx 作为我的网络服务器,但无法正确实现这一点。我总是得到默认的“欢迎使用 nginx”页面而不是我的 html。

这是我的 nginx 配置:

    #user  nobody;
    worker_processes  1;


    error_log  /var/log/nginx/error.log;
    events {
        worker_connections  1024;
    }


    http {
        include       mime.types;
       # include /usr/local/nginx/sites-enabled;
        default_type  application/octet-stream;


        sendfile        on;
        keepalive_timeout  65;


        server {
            listen       80;
            server_name  example.com;
            access_log /var/log/nginx/access.log;


            location / {
                root /data/www;
                index test.html;
             }
            location /images{
               root /data;
             }


            error_page 500 502 503 504  /50x.html;
            location = /50x.html {
              root   html;
            }

    }
}

对于这些 URL 来说,这工作正常:

example.com/images/example.jpg, 
example.com/test.html

但是我期望 example.com 能够获取 test.html,因为我在 location '/' 块中提供了索引模块。但是 example.com 只返回默认的“欢迎使用 nginx”页面。有人能帮我找出其中的问题吗?我想托管着陆页,但不向 example.com 添加任何 URL 附加内容。提前致谢。

答案1

尝试在“位置”块外添加根和索引行:

...
access_log /var/log/nginx/access.log;

root /data/www;
index test.html;

location / {
...

相关内容