AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1157827
Accepted
learningtech
learningtech
Asked: 2024-04-13 01:32:06 +0800 CST2024-04-13 01:32:06 +0800 CST 2024-04-13 01:32:06 +0800 CST

nginx 的位置块配置错误?一直显示404

  • 772

我对 nginx 很陌生。http://192.168.0.37/hls当我访问或访问时,我收到 404 not found http://192.168.0.37/hls/。

这是我的/etc/nginx/nginx.conf文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

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

        ##
        # Gzip Settings
        ##

        gzip on;


        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
        server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name _;

        root /var/www/html;
        index index.html;

        location /hls {
                root /var/www/html;
                index testtest.html;
            }
        }
}

我的目录里没有任何东西/etc/nginx/sites-enabled/。两个文件/var/www/html/index.html和/var/www/html/testtest.html均由其拥有www-data并具有755权限。

/var/www/html/testtest.html为什么我访问http://192.168.0.37/hls或时看不到内容http://192.168.0.37/hls/?


然而,我能够看到http://192.168.0.37/testtest.html

nginx
  • 1 1 个回答
  • 59 Views

1 个回答

  • Voted
  1. Best Answer
    Richard Smith
    2024-04-13T02:50:15+08:002024-04-13T02:50:15+08:00

    Nginx 正在寻找位于 的文件/var/www/html/hls/testtest.html。

    URL 的路径部分是/hls/。location /hls选择块来处理请求。

    该index testtest.html;指令将路径组件转换为/hls/testtest.html.

    该指令通过将根值与路径组件连接来root /var/www/html;将其转换为路径名-/var/www/html/hls/testtest.html


    或者,使用alias指令从路径组件中减去位置值,然后将其解析为路径名。

    任何一个:

    location /hls {
        alias /var/www/html;
        index testtest.html;
    }
    

    或者:

    location /hls/ {
        alias /var/www/html/;
        index testtest.html;
    }
    

    将寻找/hls/testtest.html在/var/www/html/testtest.html. 请注意,为了正确操作,location和alias值都应以 a 结尾/,或者都不以 结尾/。

    • 2

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve