【发布时间】:2021-10-25 19:16:05
【问题描述】:
我正在尝试学习 nginx,这个简单的测试在访问 localhost:81/test 时给了我 404。我基本上希望在 /test 上显示相同的索引页面。
我正在本地计算机上的 Windows 中使用 nginx。从http://nginx.org/en/docs/windows.html 下载并在 bash-terminal 中运行 ./nginx.exe 开始
tldr: localhost:81 给我 indexpage 和 localhost:81/test 给我 404
我的 nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 81 ;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
root html;
index index.html index.htm;
}
}
}
【问题讨论】:
-
Nginx 正在寻找
./html/test/index.html的文件 - 尝试使用:alias html; -
我试过 server_name localhost alias html;仍然得到 404
-
alias需要在location /test块内。见this document。 -
啊,是的,我必须从位置 /test 中删除 root 并且只使用别名
标签: nginx