nginx 本地 打开 http://localhost:81 跳转不到tomcat,求指点

tianqi2 2014-12-21 01:52:40
本地win7搭建测试环境,因80端口被别的程序占用了,我把nginx的监听端口改成81
现在我想做到,在浏览器输入 http://localhost:81 就跳转到 tomcat工程test的首页
最好是不用输入端口号81,输入http://localhost 就能跳转到tomcat工程test的首页
需呀修改哪里,请大神指点。
nginx.conf 配置如下

upstream tomcats.com {
ip_hash;
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8082 weight=1;
}

server {
listen 81;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
proxy_pass http://tomcats.com;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
2个tomcat server.xml配置如下:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" reloadable="false" docBase="E:\java\apache-tomcat-7.0.57-8081\webapps\test"> </Context>
</Host>
1,ie输入: http://localhost :8081 或 http://localhost :8082 可以打开tomcat 下的工程test的首页
2,ie输入: http://localhost :81 打开 nginx 的欢迎界面 Welcome to nginx! 但不跳转到tomcat部署下的工程test界面,这是为什么
3, ie输入 http://localhost :81/test 可以打开tomcat 下的工程test的首页
4,浏览器中输入 http://localhost 什么都打不开,浏览器直接跳转到http://www.ip686.com/了。
...全文
6704 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
木水山岚 2016-05-17
  • 打赏
  • 举报
回复
引用 1 楼 qyj415 的回复:
既然80端口被占用了,端口是要输入的。 ie输入 http://localhost :81/test 可以打开tomcat 下的工程test的首页 --》说明你的nginx配置是正确的! ie输入: http://localhost :8081 或 http://localhost :8082 可以打开tomcat 下的工程test的首页-》http://localhost :8081/test 能不能访问? 感觉nginx的配置没错。。。
感谢回复 找到问题了 我在windows 也装了次,配置下之后访问 http://localhost:10080/myapp/index.jsp 能 直接跳转到 本身在8080端口的 tomcat的项目 为了安装 /etc下面的默认 nginx 配置 我使用了apt-get install nginx 这个会在 /etc/nginx 下默认安装 一个nginx 服务,然后 无论怎么启动都是启动这个里面的nginx
独行码夫 2014-12-25
  • 打赏
  • 举报
回复
既然80端口被占用了,端口是要输入的。 ie输入 http://localhost :81/test 可以打开tomcat 下的工程test的首页 --》说明你的nginx配置是正确的! ie输入: http://localhost :8081 或 http://localhost :8082 可以打开tomcat 下的工程test的首页-》http://localhost :8081/test 能不能访问? 感觉nginx的配置没错。。。

25,985

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧