【问题标题】:How to point nginx to my index.html location?如何将 nginx 指向我的 index.html 位置?
【发布时间】:2020-06-12 12:26:33
【问题描述】:

我正在尝试使用 nginx 设置测试服务器块。我尝试了很多方法,但 test.myserver.com 总是向我显示 404。我的目标是在 /var/www/test/html/index.html 中显示 index.html。

这是我目前所拥有的:

server {
        listen 80;
        listen [::]:80;

        # SSL configuration
        #
        listen 443 ssl;
        listen [::]:443 ssl;


        root /var/www/test;
        index index.html index.htm index.nginx-debian.html;
        server_name test.myserver.com www.test.myserver.com;

        location ^~ /html {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files index.html $uri $uri/ / =404;
        }

        location / {
                index /html/index.html;
        }

如您所见,我已经在尝试不同的方式。我从here 获得了 ^~ 文件夹位置的想法。

那么:为什么 nginx 会给我 404,我该如何解决?

【问题讨论】:

  • 为什么不设置root /var/www/test/html;,因为那似乎是正确的文档根目录?

标签: nginx http-status-code-404


【解决方案1】:

所以我终于发现我的默认服务器块配置搞砸了。基本上,由于我不知道的原因,我先前存在的 nextcloud 实例似乎已接管为默认服务器。仅此一项可能不会做太多,但是 /etc/nginx/conf.d/nextcloud.conf 文件将 nextcloud 设置为默认服务器,它集成了其他服务器块,如 /etc/nginx/sites-enabled 并添加 nextcloud 服务器块下运行的相同标签。 一旦我从 test.myserver.com 服务器块中删除了一大堆不必要的 location ~location / 标签 within /etc/nginx/conf.d/nextcloud.conf(不在站点可用版本中),一切都开始正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 2019-02-07
    • 2012-11-09
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多