Reputation: 2480
I have Spring boot and Angular app in Tomcat Container deployed on Server. It works totally fine on localhost.
Now i am trying to map my domain with the application.
when i call my domain then api calls from Angular to Spring are not getting executed. Since they are on same server i am using localhost to call the api's from angular to spring. which works on my server browser itself but not somewhere else which is clear to me why its not working.
but i am not totally sure how to go around it.
here is my nginx configuration
server {
listen 80;
server_name localhost mydomain mydomain;
#access_log logs/host.access.log main;
location {
root html;
proxy_pass http://mydomain:8080;
index index.html index.htm;
}
}
Tomcat configuration :
<Host name="mydomain" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Alias>mydomain</Alias>
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
</Host>
My questions are :
Should i use the Server IP while calling the API's from Angular to Spring ? will it work ?
Second question is when i call my domain it redirects to tomcat manager page. I want it to go to localhost:8080/myApp. I tried proxy_pass as http://mydomain:8080/myapp & http://localhost:8080/myapp but still no success.
Any pointers for both of these questions would be highly appreciated. For any information i am available here.
Thankss
Upvotes: 1
Views: 1525
Reputation: 108
If you want to redirect to /web mapping when a user hits 'mydomain.com', you can add configuration like the following to your nginx:
server {
listen 8080;
location / {
proxy_pass mydomain.com/web;
}
}
This will be listening to port 8080 and directing/appending all the requests to /web
Upvotes: 0
Reputation: 108
Yes, you'd need to use server IP while calling the API. The reason for that being when the client requests your Angular website, the code is rendered on his website. Now when the angular website initiates an API call, it tries to hit ip localhost
which means local with respect to the client browser, which is not the case as you meant local with respect to the Angular website.
With regards to your second question, you want to hit your domain and need your website to be loaded by the root path, right?
Upvotes: 1