V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
love
V2EX  ›  NGINX

nginx 要设置主页显示指定文件的内容要怎么做?

  •  
  •   love · 2019-05-16 10:13:48 +08:00 · 1661 次点击
    这是一个创建于 1800 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想把 /* 指定到我的后端程序, 但是单独把 / 指定到一个静态文件 /myapp/static/index.html

    如果是

    location = / {
      alias /myapp/static/index.html;
    }
    
    location / {
      proxy_pass http://127.0.0.1:8000;
    }
    

    会导致 error log: "/myapp/static/index.htmlindex.html" is not a directory

    如果

    location = / {
      alias /myapp/static/;
    }
    

    就会 404, 这是要闹哪样。

    怎么才能指定 / 到那个 index.html 呢?

    第 1 条附言  ·  2019-05-16 11:15:46 +08:00
    解决了。

    之前 google 的这个文章有错误 https://www.tollmanz.com/nginx-location-match-homepage/
    还要加上 location = / {} 最终是

    location = / {} #这里一定要加一个空的语句,不知道为啥
    location = /index.html {
    alias...
    }
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1093 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 18:38 · PVG 02:38 · LAX 11:38 · JFK 14:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.