We have a QA version, a UAT version, and a DEV version of webapp. Users need to access these via http://uat.company.com:41002/webapp
, http://qa.company.com:41002/webapp
, and http://dev.company.com:41002/webapp
. There is also a different webapp on port 41001 and also on port 8080 they will need to access.
These url's are required to be available externally to the company, and we only have one public ip address they can be accessed on. As such DNS records need all 3 address to point to one IP. On that single IP address, a server resides running nginx. in the background I need for each url to point to a different server
http://uat.company.com --> 123.123.123.1
http://qa.company.com --> 123.123.123.2
http://dev.company.com --> 123.123.123.3
I'm afraid I don't know the correct terminology, however the remainder of the URI and the port must also be carried over to the ip address. I.e. if someone visits
http://uat.company.com:41002/webapp/somepage`
it will appear as though that is the page they have visited, but really they will be looking at
http://123.123.123.1:41002/webapp/somepage
or if they visited
http://qa.company.com:8080/static/home.html
they would really be looking at
http://123.123.123.2:8080/static/home.html
but their browser would still say http://qa.company.com:8080/static/home.html
I have tried
server {
server_name uat.company.com;
listen 41001;
listen 41002;
listen 8080;
location / {
proxy_pass http://123.123.123.1:$server_port$uri;
proxy_set_header Host $host;
}
}
however this gives me a bad gateway 502 page with log: 2015/01/28 16:04:49 [crit] 30571#0: *1 connect() to 123.123.123.1:41002 failed (13: Permission denied) while connecting to upstream, client: 172.23.128.245, server: uat.company.com, request: "GET /webapp/ HTTP/1.1", upstream: "http://123.123.123.1:41002/webapp/", host: "uat.company.com:41002"
I hope this is more clear.
Update From Xaviers suggestion that SELinux might have been hampering, I have disabled it and I do get further. Using the nginx config above now seems to be connecting to the second server: The port however is still not carried through. I am calling
uat.company.com:41002/webapp/
This would, if calling the service directly, redirect to
uat.company.com:41002/webapp/spring/config/main
However what is happening through the proxy is that it is returning or ending up at
uat.company.com/webapp/spring/config/main
and thus failing to load a page...