服务器设置和库
我正在编写一个带有Jersey 2.26的Java Web应用程序(用于RESTFul API开发)。我的端口8080上运行的Tomcat服务器在NGINX后面运行(作为端口80上的反向代理),除了以下情况外,一切正常。
问题:
当tomcat以有效负载响应时,POST方法返回404错误。我认为错误来自NGINX,因为404错误页面看起来不像来自Tomcat服务器的常用404消息(一个灰蓝色和白色)。我将NGIN配置添加到页面底部。在我看来,当响应有负载时,NGINX和Tomcat之间的连接丢失/断开。
以下3个代码片段捕获3种方法,我试图隔离问题。我有其他应用程序在相同的服务器配置上运行使用Servlets而不是Jersey JEE的东西,它们都工作正常。只有使用JAX-RS api的应用程序才有问题。每个sinippet都包含对端口80(NGINX)和8080(Tomcat)发出POST请求的结果的描述。
代码段1:
@POST
@Path("/upload")
public Response upload(@Context HttpServletResponse response) throws Exception {
return Response.ok().build();
}
Snippet 2:希望能够正常使用,因为它的代码正确
@POST
@Path("/upload")
public Response upload(@Context HttpServletResponse response) throws Exception {
String output = "HELLO";
System.out.println("Request reached server");
return Response.status(200).entity(output).build();
}
摘录3:
@POST
@Path("/upload")
public void upload(@Context HttpServletResponse response) throws Exception {
response.getWriter().write("HELLO\n");
response.getWriter().flush();
response.getWriter().close();
}
404错误回复:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.1</center>
</body>
</html>
NGINX config
server {
listen 80;
server_name domainname;
client_max_body_size 2000m;
gzip on;
gzip_proxied any;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
expires max;
root /usr/local/nginx/html;
#Static files
location ~ \.(js|css|jpeg|jpg|png|scss|ttf|woff|woff2) {
root /home/user/domainname;
index index.html index.htm;
}
location ~ /.well-known {
allow all;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_cookie_path ~*^/.* /;
proxy_pass http://127.0.0.1:8080/tomcat/;
proxy_max_temp_file_size 1024m;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
}
感谢任何解决此问题的努力......