Link Domain with Nginx and Tomcat with a specific Port and Folder - windows

I have a JSP application running on a Tomcat server with Port 8070
the root directory of the application is called myapp and it's accessed via localhost:8070/myapp/
Now I am trying to host it under a domain myapp.com on a Windows VM with Nginx and tomcat
Could someone help me how to do the Nginx configuration for the above scenario?

Related

How to access a web application running as a container in ubuntu from my windows system

I am running a web application(copied from github examples) that is running as a container in a remote ubuntu VM. The application is a Node JS application that is using mysql database. I brought the application up using docker-compose in ubuntu.
The application came up as http://172....:3000 using a network port. The ip address is displayed in the docker-compose terminal. In the ubuntu system, when i do curl http://172....:3000, it gives a proper success response. The ip address is a container network address. It is not the VM's ip address. There is no firewall.
How to access the web application from my windows 7 machine. When I tried accessing using http://VM Ip address:3000, it is not hitting ubuntu system. I am not getting any message in the docker-compose terminal. Can anyone help here ?
ports:
- "3031:3000"
similar line in your docker compose means you have published port 3000 of your container to port 3031 of your Ubuntu VM.
now you can access your client service as http://<ubuntu-ip>:3031 but before this, you need to allow access to port 3031

Deploy springboot application and react application to ubuntu server

I created a simple application, which consists of a reactjs frontend and a spring boot app as backend. It works fine on my local environment; with the react app running on port 3000, and the spring app running on port 9000.
I am trying to host this application in the staging environment. I want to host both the reactjs and spring boot app on a ubuntu server that I have on digitalocean. I have managed to deploy the reactjs frontend using nginx and now I want to deploy the backend using apache2.
I am having difficulty deploying the Spring boot app. I have generated a WAR file.
In my react application I call the backend spring app to serve as the api to the frontend to the browser. I have set up apache app to listen on port 9000 see below:
<VirtualHost *:9000>
ServerName 46.101.34.160
ServerAdmin webmaster#localhost
DocumentRoot
/var/www/html/BackEndBookingAndCollections
</VirtualHost>
My configuration details for the frontend goes as follows in the file;
/etc/nginx/sites-available/FEBookingAndCollections
The contents is the following:
server {
listen 80;
root /var/www/FEBookingAndCollections/build;
listen [::]:80 default_server;
server_name 46.101.34.160;
index index.html index.htm;
location / {
try_files $uri /index.html;
}
location /api/bookings/ {
proxy_pass http://46.101.34.160:9000/api/bookings;
}
}
In google chrome's browser I get the following error:
Failed to load resource: net::ERR_CONNECTION_REFUSED :9000/api/bookings:1
With spring boot, you don't have to use external Tomcat. You can package your app to jar with embedded tomcat. You can find more info here - https://www.baeldung.com/deployable-fat-jar-spring-boot.
You can't deploy war file without a server. Just follow bellow steps
1) install tomcat
2) find tomcat webapps path ( /usr/local/tomcat/webapps )
3) copy your war file to webapps. ( use scp )
4) make sure your war file and tomcat listen on same port. 8080 or 9000
5) proxy your api though apache

Deploying gradle spring application on a 1and1 cloud server

I have an apache/2.4.18 ubuntu server and I want to host my spring application on it. I generated a JAR file and can run it on the server. It starts an embedded tomcat server on port 8090.
However when i navigate to 'my-site-ip:8090' the connection times out.
I have zero experience deploying web applications so any help would be appreciated.
I've created a TCP rule for port 8090 and still no joy.
The solution was adding a proxy to the Myapp.conf file as below:
ProxyRequests off
ProxyPreserveHost On
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
It´s very hard to explain all the steps in one answer but you can follow these steps to get into the full configuration by your own. I did the same on my 1&1 cloud server.
First of all you need root access to your server.
Normally, on your server the port 80 and 443 should already be open. Else you can define that in the 1&1 Admin Portal. If your Server already has the apache configuration you should be able to see the apache site if you go to your server address. You can find details and the full setup if you dont have an apache installed for this step here:
How To Install the Apache Web Server on Ubuntu
The second step would be to configure a virtual host on your apache webserver.
This is cool because you can define multiple domains and there applications on your server. So http://yourServer.com(port 80 or 443 from extern) goes to yourApp1. (port 8090 from intern).
In this step you will tell apache if your enter your url to go to your app with port 8090
How To Set Up Apache Virtual Hosts on Ubuntu
The last step would be to install your spring-boot app as a service on your machine. The docs of Spring describes it very well.
Installation as an init.d Service
If you install the app as a service you are able to start and stop the app with the service command.
service myapp start
And dont forget to add the plugin for maven or gradle to your pom.xml. This is necessary to run the app as a service.
If you follow these Steps you should be able to reach you app without specify a port and be ready to go with your app in production if necessary.
The best approach for this would be to use the apache proxy. This should get it done.
https://blog.marcnuri.com/running-apache-tomcat-and-apache-httpd-on-port-80-simultaneously/

How to enable port 80 or 443 for Spring Boot app deployed with BoxFuse

Spring Boot app is configured (default) to run Tomcat on port 8080. This application gets deployed on AWS via BoxFuse tool and exposed at port 8080 (as expected/configured).
I have tried setting server port to 80 in boot application properties but it causes permission denied issue and the solution seems to be modifying iptables or reverse proxy. ipTables modification is not possible due to boxFuse image/env not being editable.
Question: Is there a way in BoxFuse to setup the spring boot application on port 80 without actually setting up another instance for reverse proxy? It is an overhead to setup an instance just for port correction since can't change the iptables.
Also, Is it possible that this application is run with root privileges on the AWS instance so that I do not need to modify iptables or set up reverse proxy?
There is a -ports.Name option available when deploying the application with BoxFuse.
Docs: https://cloudcaptain.sh/docs/gradle/run
Example:
boxfuse -ports.http=80 -env=test run myapprepo/myapp:0.1
Verified on local dev environment. For Mac, it should be run as a privileged command via sudo
sudo boxfuse -ports.http=80 run myapprepo/myapp:0.1
To add, works for 443 too.

Cannot access localhost:8080 from laravel

I have a PHP application running on homestead box. This application makes calls to another app that is running on glassfish on my localhost:8080.
When PHP application sends the request to localhost:8080, I am getting following error:
ConnectException in RequestException.php line 49:
cURL error 7: Failed to connect to localhost port 8080: Connection refused
Still I can make calls to localhost:8080 from web browser.Anyone has any suggestion?
Seeing how your application is running in Homestead (which by default is available on 192.168.10.10 and is forwarded to also be accessible on localhost:8000) your application running on Glassfish will not have access to it using localhost:8080. This is because localhost in your vagrant box (Homestead) is not actually the same localhost as on the host machine.
What you could do is grab the ip address from the host machine and connect to it from your application running in Homestead.
So here is how I could solve the problem. Vagrant is the guest machine running on my localhost as host machine. To access host from guest, you need to use gateway from VB.
I found this answer which helped me to access my application on localhost.

Resources