Home > other >  Nginx forwarded to tomcat, POST data loss, and to modify the browser path, how to break?
Nginx forwarded to tomcat, POST data loss, and to modify the browser path, how to break?

Time:09-26

Nginx forwarding requests to tomcat, for some reason, tomcat keep ContextPath, that is to say, during a visit to a tomcat is http://localhost:8080/Context32/, but don't want to in the browser, so think of use nginx forwarding, but not meant to, configured to the following state, pay attention to the bold and underlined part, after opening, if use permanent, browser address is correct, but unable to post data to tomcat, if use the last or without parameters, the browser is the right address, but you can post data to the tomcat, how to adjust all didn't reach the method to realize both, consult ace!

Server {
Listen, 80;
Server_name abcd.com * abcd.com;
Root/cdata/WWW/nginxwww/;
The index index. PHP index. HTML index. HTM;

# rewrite ^/Context32/(. *)/$1 permanent;
# rewrite ^/Context32/permanent;

The location/{
Proxy_pass http://localhost:8080/Context32/;
Proxy_redirect off;
Proxy_set_header Host $Host;
Proxy_set_header X - Real - IP $remote_addr;
Proxy_set_header X - Forwarded - For $proxy_add_x_forwarded_for;
Client_max_body_size 50 m.
Client_body_buffer_size 256 k;
Proxy_connect_timeout 30;
Proxy_send_timeout 30;
Proxy_read_timeout 60;
Proxy_buffer_size 16 k;
Proxy_buffers 4 32 k;
Proxy_busy_buffers_size 64 k;
Proxy_temp_file_write_size 64 k;
}

CodePudding user response:

This problem, I have just met, basic agree with you, this problem should be very common, but few discussions, there is no perfect solution, because everyone can find a compromise, stop here, do not wish to pursue perfection,
Suggested solution:
Core idea: contextPath as/,
1. Both Tomcat deployment under the ROOT
2.. Modification of Jsp contextPath as an absolute path or/,
In fact, the scheme 2 is the best way, because it can tell the contextPath completely decoupled, facilitate movement separation, documents to more hard it,
3. Someone specifically for hereat, write the corresponding module, can a try,
https://github.com/tszming/nginx-rewrite-request-body-module

CodePudding user response:

Supplement:
If ($request_method! POST)={
Rewrite/XXX (. *) $$1 permanent;
}
Because the post request generally will not affect the address bar,
In this way, they can satisfy the address bar is elegant, and POST data transmission is normal,

However, this situation is mainly used to quickly solve the problem of legacy, if it is a new planning system, or recommended scheme 2,

CodePudding user response:

Excuse me, I put the war file in tomcat webapps released inside, but there may be some engineering I upload,
Replaced the letter after the war file, the previous version of the project will be automatically deleted,, could you tell me how to release the project can keep before upload folder contents??
  • Related