请教一个 nginx 配置问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fanne
V2EX    NGINX

请教一个 nginx 配置问题

  •  
  •   fanne Apr 15, 2017 3802 views
    This topic created in 3301 days ago, the information mentioned may be changed or developed.

    现有配置内容

    server { listen 80; server_name www.abc.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; } } 

    其中, 8080 是 jboss 端口

    这样配置完后,当访问 www.abc.com 的时候,会直接跳转 www.abc.com/index.js

    那么我要怎么配置才能隐藏 index.js 的?

    12 replies    2017-04-17 11:02:32 +08:00
    BOYPT     1
    BOYPT  
       Apr 15, 2017 via Android
    你的主页输出个 iframe 代码, iframe 里面开页面。
    fanne
        2
    fanne  
    OP
       Apr 15, 2017
    @BOYPT 没懂咋意思? 能在 nginx 层面解决么
    laobaozi
        3
    laobaozi  
       Apr 15, 2017 via Android
    指定 abc.com 的 root 啊
    Famio
        4
    Famio  
       Apr 15, 2017
    #3 正解
    fanne
        5
    fanne  
    OP
       Apr 15, 2017
    @laobaozi 指定 root?
    这样?
    server {
    listen 80;
    server_name www.abc.com;
    location / {
    root /abc/ddd/pro/
    proxy_pass http://localhost:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;
    }

    }
    lmaq
        6
    lmaq  
       Apr 15, 2017
    location / {
    root html;
    index index.html index.htm;
    }
    just1
        7
    just1  
       Apr 16, 2017 via Android
    难道不应该是在 jboss 那层配置解决?
    这种情况是直接访问 localhost:8080 也会跳 index.js 吧
    Finest
        8
    Finest  
       Apr 16, 2017
    如果是 war ,那么 web.xml 有 welcome-list 指定
    AstroProfundis
        9
    AstroProfundis  
       Apr 16, 2017
    后端解析 uri 的时候考虑到 /index.js 和 / 用相同的处理方式,然后 nginx 配 rewrite, 或者 try_files
    fanne
        10
    fanne  
    OP
       Apr 16, 2017
    @hand515 对是 war 包的, web.xml 中 welcome-list 中怎么指定的,找了一圈,没找到案例。
    fanne
        11
    fanne  
    OP
       Apr 17, 2017
    @hand515 在项目中的 web.xml 找到这个 welcome-file-list ,这里指定的么?要怎么指定法?
    7 <welcome-file-list>
    8 <welcome-file>index.jsf</welcome-file>
    9 <welcome-file>index.htm</welcome-file>
    10 </welcome-file-list>
    Finest
        12
    Finest  
       Apr 17, 2017
    我 用的 springmvc
    <welcome-file-list>
    <welcome-file>/</welcome-file>
    </welcome-file-list>
    配置成上面那样,然后增加一个

    @RequestMapping(value = { "/", "/index" })
    public String index(@RequestParam(value = "id", required = false, defaultValue = "1") Long id) {
    return "forward:/js/jquery-2.1.1.min.js";
    }
    About     Help     Advertise     Blog     API     FAQ     Solana     2811 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 42ms UTC 15:32 PVG 23:32 LAX 08:32 JFK 11:32
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86