V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
love
V2EX  ›  NGINX

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

  •  
  •   love · May 16, 2019 · 2131 views
    This topic created in 2538 days ago, the information mentioned may be changed or developed.

    我想把 /* 指定到我的后端程序, 但是单独把 / 指定到一个静态文件 /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 呢?

    Supplement 1  ·  May 16, 2019
    解决了。

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

    location = / {} #这里一定要加一个空的语句,不知道为啥
    location = /index.html {
    alias...
    }
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   958 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 20:48 · PVG 04:48 · LAX 13:48 · JFK 16:48
    ♥ Do have faith in what you're doing.