我在端口80上运行Nginx,在端口8080上运行Tomcat。
我在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。我看到示例Web应用程序打开了。
我打开了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示例页面。但是,当我点击应用程序内部的任何链接(如“servlets”)时,我会得到404。
您知道如何将请求转发给Tomcat,以便将内容从Tomcat返回给Nginx吗?
感谢 -Sonam
答案 0 :(得分:2)
您应该从配置中删除它:
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;