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

请教一个 nginx 配置问题

  •  
  •   fanne · 2017-04-15 18:30:09 +08:00 · 3196 次点击
    这是一个创建于 2561 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现有配置内容

    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 条回复    2017-04-17 11:02:32 +08:00
    BOYPT
        1
    BOYPT  
       2017-04-15 18:42:16 +08:00 via Android
    你的主页输出个 iframe 代码, iframe 里面开页面。
    fanne
        2
    fanne  
    OP
       2017-04-15 18:49:19 +08:00
    @BOYPT 没懂咋意思? 能在 nginx 层面解决么
    laobaozi
        3
    laobaozi  
       2017-04-15 18:55:39 +08:00 via Android
    指定 abc.com 的 root 啊
    Famio
        4
    Famio  
       2017-04-15 20:01:07 +08:00
    #3 正解
    fanne
        5
    fanne  
    OP
       2017-04-15 20:57:13 +08:00
    @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  
       2017-04-15 23:55:45 +08:00
    location / {
    root html;
    index index.html index.htm;
    }
    just1
        7
    just1  
       2017-04-16 00:16:42 +08:00 via Android
    难道不应该是在 jboss 那层配置解决?
    这种情况是直接访问 localhost:8080 也会跳 index.js 吧
    hand515
        8
    hand515  
       2017-04-16 08:10:36 +08:00
    如果是 war ,那么 web.xml 有 welcome-list 指定
    AstroProfundis
        9
    AstroProfundis  
       2017-04-16 08:46:47 +08:00
    后端解析 uri 的时候考虑到 /index.js 和 / 用相同的处理方式,然后 nginx 配 rewrite, 或者 try_files
    fanne
        10
    fanne  
    OP
       2017-04-16 10:18:05 +08:00
    @hand515 对是 war 包的, web.xml 中 welcome-list 中怎么指定的,找了一圈,没找到案例。
    fanne
        11
    fanne  
    OP
       2017-04-17 10:33:18 +08:00
    @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>
    hand515
        12
    hand515  
       2017-04-17 11:02:32 +08:00
    我 用的 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";
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2447 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:08 · PVG 09:08 · LAX 18:08 · JFK 21:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.