› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
learnshare
V2EX  ›  NGINX

是否能实现请求 www/path* 返回 www/index.html 但不做 302 重定向?

  •  
  •   learnshare ·
    learnshare · Jul 18, 2016 · 3690 views
    This topic created in 3760 days ago, the information mentioned may be changed or developed.

    1. 背景

    在做 Angular.js 的单页面应用,没玩过 Nginx 。

    之前一直是用 abc.com/#/path 这种形式的路由,但 Angular.js 本身也 支持 abc.com/path 这种形式的路由。

    那一般来说,服务器会给 abc.com/path 这个请求返回 www/path/index.html ,但 Angular.js 应用的入口是 www/index.html 。

    2. 需求

    用户访问 www/ 及其子目录时,都返回 www/index.html ,但不做 302 重定向(保持原来的 URL )。

    Nginx 的配置是?

    7 replies  •  2016-07-19 23:36:49 +08:00
    jswh
    jswh
    Jul 18, 2016
    1
    具体配置补贴,自己补贴 nginx rewrite 吧,如果版本比较新,可以搜 nginx try
    jswh
    jswh
    Jul 18, 2016
    2
    @jswh 自己补贴 -> 自己 google
    lslqtz
    lslqtz
    Jul 19, 2016
    3
    alias ?
    sdzxwxlsj
    sdzxwxlsj
    Jul 19, 2016
    4
    rewrite
    learnshare
    learnshare
    OP
    Jul 19, 2016
    5
    @jswh
    @lslqtz
    @sdzxwxlsj

    正在摸索 Nginx ,今天应该能写出一个满足需要的配置
    learnshare
    learnshare
    OP
    Jul 19, 2016
    6
    @jswh
    @lslqtz
    @sdzxwxlsj

    目前已经可用。麻烦几位帮我看一下,是否合理:

    https://gist.github.com/LearnShare/276374fbbc46cfde8bea6e2d46ec32f7

    Thanks :P
    garrydzeng
    garrydzeng
    Jul 19, 2016❤️1
    7
    server {
    location ~ ^/www {
    rewrite ^ /index.html last;
    }
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4990 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 01:17 · PVG 09:17 · LAX 17:17 · JFK 20:17
    ♥ Do have faith in what you're doing.