请教一个 nginx 配置问题

2017-04-15 18:30:09 +08:00
 fanne

现有配置内容

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 的?

3233 次点击
所在节点    NGINX
12 条回复
BOYPT
2017-04-15 18:42:16 +08:00
你的主页输出个 iframe 代码, iframe 里面开页面。
fanne
2017-04-15 18:49:19 +08:00
@BOYPT 没懂咋意思? 能在 nginx 层面解决么
laobaozi
2017-04-15 18:55:39 +08:00
指定 abc.com 的 root 啊
Famio
2017-04-15 20:01:07 +08:00
#3 正解
fanne
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
2017-04-15 23:55:45 +08:00
location / {
root html;
index index.html index.htm;
}
just1
2017-04-16 00:16:42 +08:00
难道不应该是在 jboss 那层配置解决?
这种情况是直接访问 localhost:8080 也会跳 index.js 吧
hand515
2017-04-16 08:10:36 +08:00
如果是 war ,那么 web.xml 有 welcome-list 指定
AstroProfundis
2017-04-16 08:46:47 +08:00
后端解析 uri 的时候考虑到 /index.js 和 / 用相同的处理方式,然后 nginx 配 rewrite, 或者 try_files
fanne
2017-04-16 10:18:05 +08:00
@hand515 对是 war 包的, web.xml 中 welcome-list 中怎么指定的,找了一圈,没找到案例。
fanne
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
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";
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/355112

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX