【问题标题】:NGINX simple proxy doesnt work, get 404 on locationNGINX 简单代理不起作用,在位置上获取 404
【发布时间】: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


【解决方案1】:

必须在location /test-block 中将root html 替换为alias html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多