How to do a redirect behind Nginx - java

My Tomcat server sits behind an Nginx reverse proxy.
I configured RemoteIpValve in Tomcat to replace hostname, port and scheme. Tomcat works on localhost:8080.
Tomcat valve (server.xml)
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
protocolHeader="x-forwarded-proto"
proxiesHeader="x-forwarded-by" />
When i redirect from https://example.com/pages/MyForm.jsp to https://example.com/pages/MyForm.jsp?message=Something, it works correctly,
but when i try to redirect from https://example.com/pages/MyForm.jsp to https://example.com/pages/AnotherPage.jsp?message=Something the
site can't be reached.
Unlike the first example request, the second one displays port 8080 in the location of Response Headers.
location: https://example.com:8080/pages/AnotherPage.jsp?message=Something`
Request Method: GET
Is there any configuration that should be done in Nginx or Tomcat? How can i solve this problem?

Related

IIS rewrite rule with Tomcat 9.0

I have deployed a Spring Boot application in Tomcat in Windows Server and it's accessible on browser via http://server-name:8080/app. Now, for end users I don't want them to hit the app at port 8080, so I have configured an IIS rewrite rule
<rule name="app" enabled="true" stopProcessing="false">
<match url="^app.*" />
<action type="Rewrite" url="http://server-name:8080/{R:0}" logRewriteUrl="true" />
</rule>
Now, when I hit http://server-name/app, it works, but the subsequent calls are going to http://server-name:8080/app.
I am not sure if there is a problem with the IIS rule since I ran the app.war using same application.properties as
java -jar app.war --server.port=8080 --spring.config.import=application.properties
The only caveat here is I am passing context path in properties as
server.servlet.context-path=/app
and in this scenario all the URL calls go without port 8080. If anyone have any insight or solution, please share.
Please NOTE: I can't host Tomcat on port 80 as there are other apps running on port 80 which uses the API from app deployed in Tomcat.

How to use the browser to access tomcat on port 8080?

I have a remote server, and its default port is 8080, but you know the browser default use 80 port to access it, so can not access my tomcat.
How to configure it to access the tomcat's 8080 port?
It is under the windows.
If I use www.example.com:8080 in the browser I can access the server, but if I use www.example.com I can not access it.
EDIT
I use Tomcat + IIS (Server Consolidation), IIS occupy the 80 port.
You cannot access the URL on http://www.example.com because the browser will try to make a TCP connection on port 80 while tomcat is listening to post 8080.
If you want to change the port tomcat is listening to, see this question
Another option is to use a proxy in front of your tomcat server. You can use apache web server or Nginx. They can listen to port 80 and forward your request to the tomcat server on port 8080.
Update
As mentioned in the comments below, as the post80 is already taken, adding reverse proxy cannot help. Because the reverse proxy will not be able to listen to port 80.
It is recommended to see which process is using port 80 and then a proper solution can be implemented.
Update
As IIS is listening on port 80, it is recommended to configure IIS to act as the reverse proxy.
You can follow this link to do so.
You can change tomcat connector port number.
Navigate to /tomcat-root/conf folder. Within you will find the server.xml file.
Open the server.xml and search for connector port and change it.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

Gets the error without port number even when it is default port in tomcat?

I have tomcat installed on my local machine. I see it in server.xml where I have below entry
<Connector executor="tomcatThreadPool"
port="${http.port}"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="${https.port}"
acceptCount="100"
maxKeepAliveRequests="15"/>
where http.port value in catalina.properties is 8080 .
But every time I try to access my application it url http://localhost/myApp I get error
could not connect to localhost but it works fine http://localhost:8080/myApp. I am not getting why it expects
the port 8080 when it is already a default port? What should I do so that I do not have to mention port?
When you write http://localhost/myApp on the Address Bar of your Browser, the request always goes to Port 80, and not Port 8080. So the default is Port 80 here. For http://localhost/myApp to work you need to install something like Apache HTTP Server.
Then you can configure it with the help of a connector like mod_jk or mod_proxy to use http://localhost/myAppi, instead of http://localhost:8080/myApp. So that what ever request comes on Port 80 can be diverted to Port 8080 automatically.
Once you will download mod_jk, simply extract the file mod_jk.so to the modules folder of your Apache HTTP Server.
Hopefully the steps written here How to Configure Apache HTTP Server with Apache Tomcat, might help you in doing that.
On a Windows platform all you have to do is changing the port number in server.xml from 8080 to 80 and you are done.
The above is not true for Unix/Linux environments. Changing the port number might work on Windows but i think it might be slightly tricky on Unix/Solaris.
Under UNIX all ports <1024 are "privileged" ports. Only root may open a privileged port. It is still possible but keep in mind that it is not as simple as changing the port number when on Unix.
There are a number of workarounds for this.
http://raibledesigns.com/rd/entry/how_to_run_tomcat_on
http://mihail.stoynov.com/2011/04/04/howto-start-tomcat-on-port-80-without-root-privileges/
http://java-notes.com/
http://www.klawitter.de/tomcat80.html

jax-ws webservice's endpoint is always localhost

I really need your help. I read that the wsdl for a jax-ws webservice will be generated on the fly for every request. By this, the addresses like the soap endpoint will be adjusted to the request url.
In my case it, no matter wheather internal or external request, the addresses are always refered to localhost:8080.
Does sb have a clue how can I handle this issue?
Thanks in advance
Maybe I haven't described my problem very well.
I have a ws created with jax-ws
Its deployed on a tomcat server 5.5.17
Access with local ip works fine http://192.168.1.20:8070/mywebservice?wsdl
Access with external ip doesn't work resp. the ws "engine" rewrites the url by using the local ip and not the external one
external.domain.de:8070/mywebservice?wsdl
For external.domain all urls in the wsdl are rewritten to the local ip
To the xsdschemaLocation and the soap:address location
Could the proxy server the problem? Request through the proxy makes the webservice think that it is an local access and not a external.
How can I prevent this behaviour on server side?Changes in web.xml or sun.jax (Changes on client side are regrettably not possible)
This is a classic problem when accessing web-services thru external proxies.
For this to work properly, you have to do the following
1) Add another HTTP connector in your Tomcat's server.xml. Say on port 8071, just copy the 8080 Connector Dfn. and set the port to 8071.
2) And in that Connector's defn. you have to add the external IP and Port as proxyHost and proxyPort.
i.e. your server.xml should contain one more Connector entry some thing like this
<Connector port="8071" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
proxyHost="external.domain.de" proxyPort="8070" />
And make sure that Connections to external.domain.de on port 8070, get forwarded to 192.168.1.20 and port 8071, instead of 8070.
I told you to setup a new connector, assuming you would want to access the WS internally as well as externally. That way the internal port connector on 8070, does not use proxyhost and change the hostname for internal requests, but any requests coming from external sources via external.domain.de on port 8071 , will get the external.domain.de as hostname and 8070 as port.
If your WS is going to be accessed only from external clients, then you don't really need 2 connectors, just add the proxyHost and proxyPort directives to the 8070 connector and you're done.
But be warned, that even internal requests, will now see the hostname as external.domain.de.
More info # https://tomcat.apache.org/tomcat-5.5-doc/config/http.html#Proxy_Support

Tomcat 5.5 virtual host with appbase

I'm trying to create a virtualhost in Tomcat 5.5. Up till now I've created the Host entry
<Host name="www.nikoslianeris.gr" appBase="test"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="test" prefix="mydoamin_access_log." suffix=".txt"
pattern="combined" resolveHosts="false"/>
</Host>
and everything is ok with that. The problem is that when I put my app in the appbase directory nothing happens. I mean, I can see from the admin console the new virtual host bat when I type the url nothing happens. I don't know what the problem might be! I found many tutorials on the subject and did what they said but nothing happens!
just brainstorming, but have you mapped www.nikoslianeris.gr to your local machine in your hosts file or a local DNS? ie any request to that domain should result in the request being sent to your machine, then the request gets sent to tomcat, and only then does the virtual host settings above kick in.
In theory you can test if this is the case using ping or traceroute on that domain, or by telnetting to your local machine on the Tomcat port and writing a sample HTTP request and also specify the "Host:www.nikoslianeris.gr" in the HTTP header. In theory.

Categories

Resources