Redirect Apache to Tomcat on Vesta CP - java

I have a VPS server with Ubuntu 18 O.S. In this VPS I have installed VESTA CP, which comes with Apache 2 and Nginx. After that I have intalled Tomcat 9(port 8082) to serve a Java Spring based webapp.
If I enter the address "serverIP:8082/AppFolder" I can access the app, but I want to redirect the apache server to the tomcat one, so I can write the domain name and load the webapp.
I have tried .htaccess file but it shows an apache error page. I have no permission to view this file is the message.
What can I do to solve this?
-Nginx config:
location / {
proxy_pass http://IP:8080;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
root /home/admin/web/webapp.com/public_html;
access_log /var/log/apache2/domains/webapp.com.log combined;
access_log /var/log/apache2/domains/webapp.com.bytes bytes;
expires max;
try_files $uri #fallback;
}
}
location /error/ {
alias /home/admin/web/webapp.com/document_errors/;
}
location #fallback {
proxy_pass http://IP:8080;
}
-Apache config:
<VirtualHost IP:8080>
ServerName webapp.com
ServerAlias www.webapp.com
ServerAdmin info#webapp.com
DocumentRoot /home/admin/web/webapp.com/public_html
ScriptAlias /cgi-bin/ /home/admin/web/webapp.com/cgi-bin/
Alias /vstats/ /home/admin/web/webapp.com/stats/
Alias /error/ /home/admin/web/webapp.com/document_errors/
#SuexecUserGroup admin admin
CustomLog /var/log/apache2/domains/webapp.com.bytes bytes
CustomLog /var/log/apache2/domains/webapp.com.log combined
ErrorLog /var/log/apache2/domains/webapp.com.error.log
<Directory /home/admin/web/webapp.com/public_html>
AllowOverride All
Options +Includes -Indexes +ExecCGI
php_admin_value open_basedir /home/admin/web/webapp.com/public_html:/home/admin/tmp
php_admin_value upload_tmp_dir /home/admin/tmp
php_admin_value session.save_path /home/admin/tmp
</Directory>
<Directory /home/admin/web/webapp.com/stats>
AllowOverride All
</Directory>
<IfModule mod_ruid2.c>
RMode config
RUidGid admin admin
RGroups www-data
</IfModule>
<IfModule itk.c>
AssignUserID admin admin
</IfModule>
IncludeOptional /home/admin/conf/web/apache2.webapp.com.conf*
</VirtualHost>
Thanks.

Finally I have found an answer...editing the config file of nginx:
proxy_pass http://IP:8082; <--TOMCAT PORT
root /home/admin/web/webapp.com/public_html; <--JSP PAGES PATH
Default config file has the Apache port and apache html pages path.
I suppose this can be done using apache proxy_mod, but I donĀ“t know which way is better...if anyone can explain the two ways(via apache or via nginx) I apreciate it.

Related

NGINX configuration in App Engine Flexible custom environment

We have a Java/Spring Boot web application on Google App Engine Flexible environment. One of the endpoints is for file uploads and often times, NGINX is buffering these requests to disk: a client request body is buffered to a temporary file /var/cache/nginx/client_temp/0000000001.
I'm having trouble determining where the NGINX configuration is in this case. So far I've tried different approaches via the Dockerfile. How do I configure NGINX or provide a nginx.conf file in Google App Engine Flexible? Listing my Dockerfile and nginx.conf file specifying the client_body_buffer_size.
Dockerfile:
FROM openjdk:8
VOLUME /tmp
ARG JAR_FILE=target/user-app.jar
COPY ${JAR_FILE} app.jar
COPY config/nginx/nginx.conf /etc/nginx/nginx.conf
# create log dir configured in nginx.conf
RUN mkdir -p /var/log/app_engine
# Create a simple file to handle heath checks. Health checking can be disabled
# in app.yaml, but is highly recommended. Google App Engine will send an HTTP
# request to /_ah/health and any 2xx or 404 response is considered healthy.
# Because 404 responses are considered healthy, this could actually be left
# out as nginx will return 404 if the file isn't found. However, it is better
# to be explicit.
RUN mkdir -p /usr/share/nginx/www/_ah && \
echo "healthy" > /usr/share/nginx/www/_ah/health
ARG SPRING_PROFILES_ACTIVE
ENV SPRING_PROFILES_ACTIVE=$SPRING_PROFILES_ACTIVE
ENTRYPOINT ["java","-jar","/app.jar"]
nginx.conf:
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_body_buffer_size 500M;
# Logs will appear on the Google Developer's Console when logged to this
# directory.
access_log /var/log/app_engine/app.log;
error_log /var/log/app_engine/app.log;
gzip on;
gzip_disable "msie6";
server {
# Google App Engine expects the runtime to serve HTTP traffic from
# port 8080.
listen 8080;
}
}

How do I use http://example.com instead of http://example.com/Example/?

Here /Example is my .war file and all file in it in .jsp format.
I have access my .war via http://example.com:8080.
How can I access it via http://example.com?
You can find the anwser in the Tomcat documentation at: https://tomcat.apache.org/tomcat-6.0-doc/config/http.html
You can do one of the following:
1) Edit the conf/server.xml file in your tomcat installation folder. (I assume you are using tomcat, if not - look for an equivalent file for your web server). Here is a sample entry (edit the port here)
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
Restart tomcat.
2) The second way is to use re-directs or url-rewrites to forward traffic to port 8080 to port 80.
Change the http connector port from 8080 to 80 in your tomcat's server.xml. Look for <Connector tag and there you will see port attribute
Rename your WAR file to ROOT.war, the name ROOT for tomcat means that it is the root context (all capital letters) and the name is reserved for such this purpose. See https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming
Next, change the listener port in conf/server.xml from 8080 to 80.

How to deploy a java application as root in tomcat without allow access to other webapps

I have a java application.war and I copied the file to tomcat7/webapps directory.
I'm able to access it with www.application.com/application (My domain points to ip 200.xyz.12.jk:8080) BUT
I want to access it through www.application.com (without the name of the folder inside webapps directory)
Also i dont want to allow access to other folders inside webapps.
I have tried some topics but didnt succeed.
Failed to help:
Deploying my application at the root in Tomcat
https://josefbetancourt.wordpress.com/2011/02/12/tomcat7-change-root-app/
Tomcat 6: How to change the ROOT application
Thank you so much
Place your tomcat under apache http server then point it to tomcat's AJP protocol.
Example of Apache httpd.conf configuration:
Listen 80
ProxyPass / ajp://application.com:8009/application
In tomcat server.xml file you should have below ajp connector:
<Connector port="8009" protocol="AJP/1.3" />
As a result www.application.com/ url points to the application entire directory over ajp protocol.
Hope this will help you.

how to open default page in browser from Apache web server..?

I have started Apache Web server and put all the required configuration in httpd.conf file like
DocumentRoot "c:/Apache2/htdocs"
<Directory "c:/Apache2/htdocs">
<Directory> DirectoryIndex
when i'm opening localhost in browser that time it not opening index.html document which is stored in htdocs directory. can someone please suggest my what i'm missing here, Thanks in Advance .
At the end you have to write the name of file 'index.html'
DocumentRoot "c:/Apache2/htdocs"
<Directory "c:/Apache2/htdocs">
<Directory> DirectoryIndex index.html

How to create localhost domain management for windows in php?

I am crazy about this thing, but i want to make it myself in php itself.
I have installed the following in my system.
WAMP Server 2.2 which includes following
Apache Web Server Version 2.2.222
MySQL Server Version 5.5.24
PHP Version 5.3.13
OS Version Windows 8 64Bit
Location of Hosts file:
C:\Windows\System32\Drivers\etc\hosts
Location of WAMP Server:
C:\wamp
Location of Apache Web Server:
- C:\wamp\bin\apache\apache2.2.22
- C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf
Location of MySQL Server:
C:\wamp\bin\mysql\mysql5.5.24
Location of PHP:
C:\wamp\bin\php\php5.3.13
I have simple example of Create the VHost in localhost
e.g. I want to create simple domain www.mylocalsite.com on 80 port
For that I have following steps:
(1) Enagle Apache modules
rewrite_module
vhosts_alias_module
(2) Open httpd.conf file to enable Vhost settings
C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf
Virtual hosts
Include conf/extra/httpd-vhosts.conf // Remove the # before Include and save file
(3) Add VHost entry in httpd-vhosts.conf file
<VirtualHost *:90>
DocumentRoot "C:/mylocalsite.com/"
ServerName www.mylocalsite.com
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "C:/mylocalsite.com/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "C:/mylocalsite.com/logs/error.log" // Logs folder should be exists
CustomLog "C:/mylocalsite.com/logs/access.log" common
</VirtualHost>
(4) Add entry in hosts file
Open file in Notepad with Admin Permission C:\Windows\System32\Drivers\etc\hosts
add following line at end of the file and Save it.
127.0.0.1 www.mylocalsite.com
(5) Restart the (From WAMP) Apache Web Server and run in browser http://www.mylocalsite.com/ will work.
Now, My Question is how can I do the above steps in dynamic nature using PHP/JSP or any other language.
Suppose I will create one Form in HTML with following fields and when submit it will create new MySQL entry for that domain.
EDIT:
Domain Type: select option or Radio Options ( Root/Sub-Domain )
Sub-Domain Name ( Optional ): Text field
Domain Name: Text field
Project Path: text field
Log Folder Path: text field
Tmp Folder Path: text field
Database Type: text field ( mysql/pgsql )
<Submit>
when i click on button it will automatically create the domain entry in hosts file, vhosts entry in httpd-vhosts.conf file.
And, when restart the Apache server it will run automatically created domain or sub-domain dynamically.
Can anyone knows how can i established the following things in any language for local system only?
Don't use web form. You can see my demo with batch file:
(1) Create vhost template template.txt
<VirtualHost *:90>
DocumentRoot "_ROOT_"
ServerName _DOMAIN_
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "_ROOT_">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "_ROOT_/logs/error.log"// Logs folder should be exists
CustomLog "_ROOT_/logs/access.log" common
</VirtualHost>
(2) Create add_vhost.bat
#echo off
set /p domain=Domain (www.mylocalsite2.com):
set lineHost=127.0.0.1 %domain%
REM Create the domain entry in hosts file
echo %lineHost% >> C:\Windows\System32\drivers\etc\hosts
set /p folder=Folder (C:/mylocalsite2.com/):
REM Create vhost entry in httpd-vhosts.conf file
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (template.txt) do (
set str=%%i
set str=!str:_ROOT_=%folder%!
set str=!str:_DOMAIN_=%domain%!
echo !str! >> C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf
)
(3) Run add_vhost.bat as Administrator (to write HOSTS file)

Categories

Resources