One: First, let’s publish a web service
package com.ws.service;
public interface IUserService
{
public String getUserName(String id);
}
package com.ws.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public class UserService implements IUserService
{
@WebMethod
public String getUserName(@WebParam(name=”id”) String id)
{
return “User:” + id;
}
}
package com.ws.service;
import javax.xml.ws.Endpoint;
public class Server
{
public static void main(String[] args)
{
Endpoint.publish(“http://0.0.0.0:6633/api/v1/user”, new UserService());
System.out.println(“ws startup ok on port ” + 6633);
}
}
The port of ws is 6633
The access address is: http://192.168.100.95:6633/api/v1/user?wsdl
Then, nginx is configured as follows.
upstream webservice {
server 192.168.10.95:6633;
}
server {
listen 6633;
location/{
proxy_pass http://webservice;
}
}
The nginx address is: 192.168.2.123
Then visit the proxy address: http://192.168.2.123:6633/api/v1/user?wsdl
The result is as follows
The address here is clearly wrong.
The solution is as follows
The nginx configuration is changed to
upstream webservice {
server 192.168.100.95:6633;
}
server {
listen 6633;
location/{
proxy_set_header Host $host:$server_port;
proxy_pass http://webservice;
}
}
The reason for this is that if you don’t configure
proxy_set_header Host $host:$server_port;
then, nginx reverse proxy to the backend, passing the Host http header as
Host=webservice
Similar Posts:
- [Solved] docker nginx localhost connection refused connect() failed (111: Connection refused)while connecting to upstream
- Fix Nginx 502 Error:upstream sent too big header while reading response header from upstream
- Nginx Error when installing the startup service failed to start a high performance web server and a reverse proxy serve
- Solve the 400 error of nginx forwarding websocket
- [Solved] Nginx reverse proxy 502 permission denied
- Nginx error 111: connection rejected [How to Solve]
- [Solved] Nginx proxy Timeout: upstream timed out (110: Connection timed out)
- Nginx Timeout Error: upstream timed out (110: Connection timed out) while reading response header from ups…
- [Solved] nginx no resolver defined to resolve..
- [Solved] MySQL Connect Error: Can’t connect to MySQL server on ‘ ‘(61)