mechille
V2EX  ›  问与答

如何设置 NGINX,使根域名不可访问,但是其他非根路径可以访问

  •  
  •   mechille · Jul 24, 2014 · 6212 views
    This topic created in 4487 days ago, the information mentioned may be changed or developed.
    简单来说就是http://aaaaa.com 返回404

    但是http://aaaaa.com/bbb/ccc 或者 http://aaaaa.com/bbb 可以访问
    10 replies  •  2014-07-25 09:29:04 +08:00
    duzhe0
    duzhe0
    Jul 24, 2014
    1
    不能访问是什么意思?404?断开连接?
    mechille
    mechille
    OP
    Jul 24, 2014
    2
    @duzhe0 404就行
    hging
    hging
    Jul 24, 2014
    3
    -,- location / 然后转向一个404页面。
    mechille
    mechille
    OP
    Jul 24, 2014
    4
    @hging 不行,因为/bbb/ccc这种路径我都是用的location /的重定向。。。
    Bviews
    Bviews
    Jul 24, 2014
    5
    把location / 放最后就好了呀。
    rails3
    rails3
    Jul 24, 2014
    6
    @mechille location = / 呢
    aa65535
    aa65535
    Jul 24, 2014
    7
    ```
    location = / {
    return 404;
    }
    ```
    可以了。
    mechille
    mechille
    OP
    Jul 24, 2014
    8
    @aa65535 感谢,成功了,那么请问可以使用 location != / 来表示「当不在根目录下的时候」吗?
    aa65535
    aa65535
    Jul 24, 2014
    9
    @mechille location 没有那个比较符的,可以这样
    ```
    location ~* /.+ {
    # do something...
    }
    ```
    使用正则匹配。
    mechille
    mechille
    OP
    Jul 25, 2014
    10
    @aa65535 试了不太好用,再麻烦大大一下,我现在是想这样:根目录返回一段文字:「PLEASE MOVE TO XXXX.COM」非根目录就rewrite。再次麻烦指教
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5053 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 06:39 · PVG 14:39 · LAX 22:39 · JFK 01:39
    ♥ Do have faith in what you're doing.