【发布时间】:2016-08-18 18:10:56
【问题描述】:
Nginx 运行在 80 端口,Tomcat 运行在 8080 端口。
我在tomcat conf/server.xml中放入如下配置:
<Host name="localhost" appBase="web apps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="examples">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
我重新启动 tomcat 并打开 localhost:8080。我看到示例网络应用程序打开了。
我打开了 nginx 文件 /etc/nginx/sites-enabled/default 并更新了位置配置:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
#put in by me
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
当我打开浏览器到 localhost 时,我可以看到 Tomcat 示例页面。但是,当我点击应用程序内部的任何链接(如“servlet”)时,我会收到 404。
你知道我如何将请求转发给 Tomcat,以便内容从 Tomcat 返回到 Nginx?
谢谢 -索南
【问题讨论】: