我对 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 正在寻找位于 的文件
/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
指令从路径组件中减去位置值,然后将其解析为路径名。任何一个:
或者:
将寻找
/hls/testtest.html
在/var/www/html/testtest.html
. 请注意,为了正确操作,location
和alias
值都应以 a 结尾/
,或者都不以 结尾/
。