when deploying locally to tomcat, I make this change (below) to server.xml, is there a way I can supply this to Elastic Beanstalk?
<Connector connectionTimeout="20000" port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol"
redirectPort="8443"/>'
thanks
'
You can do it now without providing custom AMI. Follow instructions in: http://aws.typepad.com/aws/2012/10/customize-elastic-beanstalk-using-configuration-files.html
In order to provide custom server xml create .ebextensions folder in webapp, put there custom server.xml file and add one more file: server-update.config with content:
container_commands:
replace-config:
command: cp .ebextensions/server.xml /etc/tomcat7/server.xml
Another way to implement this without replacing the entire Tomcat server.xml file is using the following in your .ebextensions folder (e.g. tomcat.config)
files:
"/tmp/update_tomcat_server_xml.sh":
owner: root
group: root
mode: "000755"
content: |
#! /bin/bash
CONFIGURED=`grep -c '<Connector port="8080" URIEncoding="UTF-8"' /etc/tomcat7/server.xml`
if [ $CONFIGURED = 0 ]
then
sed -i 's/Connector port="8080"/Connector port="8080" URIEncoding="UTF-8"/' /etc/tomcat7/server.xml
logger -t tomcat_conf "/etc/tomcat7/server.xml updated successfully"
exit 0
else
logger -t tomcat_conf "/etc/tomcat7/server.xml already updated"
exit 0
fi
container_commands:
00_update_tomcat_server_xml:
command: sh /tmp/update_tomcat_server_xml.sh
This config creates a script (files) and then runs it (container_command). The script checks the server.xml for the UIREncoding="UTF8" string and if it doesn't find it, it then adds it in using the sed command.
The nice thing about this solution is that if you upgrade your version of Tomcat (e.g. from 7 to 8) then you don't have to worry about updating the server.xml in your various WAR files.
Also, this example is for adding the UIREncoding parameter but the script is very easily adapted to add <Connector ... />' property from the original question.
Related
I am using the following example file: https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/ and have deployed it on Tomcat.
I want to put Apache in front of Tomcat. I have the following config on my Tomcat's server.xml:
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
My Apache is running on port 80, and my workers.properties looks as follows:
worker.list=jboss,tomcat
worker.jboss.port=8009
worker.jboss.host=127.0.0.1
worker.jboss.type=ajp13
worker.tomcat.port=8010
worker.tomcat.host=127.0.0.1
worker.tomcat.type=ajp13
Note that I also have JBoss running. Then my uriworkermap.properties looks as follows:
/App/*=jboss
/sample/*=tomcat
/sample=tomcat
/sample/=tomcat
The JBoss config works fine. If I go to http://localhost:8081/sample/ my webpage is displayed. But if I go to http://localhost:80/sample/ I get a
The Webpage cannot be found error. What am I doing wrong?
This is what http://localhost:8081/sample/ looks like:
you can't run a java app on apache web server. you need a servlet container like tomcat to run a java app. If you want to use apache as a gateway to your app deployed at tomcat, you can have some static file or cgi script in your apache server and that script or html file could call your app deployed at tomcat. URL http://localhost:80/sample/ is not working because it's expecting a file name sample in your apache's www (usually) directory and your probably don't have that file in there.
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.
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.
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)
I downloaded apache-tomcat-6.0.35 & put it in tomcat folder.
I did accroding to to this:
http://builddeploy.blogspot.com/2010/02/running-multiple-tomcat-instances-on.html
My tomcat directory structure is
tomcat
apache-tomcat-6.0.35
bin,conf,lib,logs,temp,webapps,work //Folders name
tomcatclpl
bin,conf,logs,temp,webapps,work //Folders name
tomcatmass
bin,conf,logs,temp,webapps,work //Folders name
and apache-tomcat-6.0.35's server.xml file port is 8085
<Server port="8005" shutdown="SHUTDOWN">
and
<Connector port="8005" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
and tomcatclpl's conf - server.xml file I have changed following
<Server port="8205" shutdown="SHUTDOWN">
and
<Connector port="8282" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
and
<Connector port="8209" protocol="AJP/1.3" redirectPort="8443" />
same like tomcatmass also i have changed the port as 8383.
My starup.bat file is:
#echo off
#echo Tomcat CLPL Service
set "CATALINA_BASE = C:\Tomcat\tomcatclpl"
set "CATALINA_HOME=C:\Tomcat\apache-tomcat-6.0.35"
C:\Tomcat\tomcatclpl\bin\startup.bat
When I run in cmd line;
C:\Tomcat\tomcatclpl>startup.bat
Tomcat MASS Service
Using CATALINA_BASE: "C:\Tomcat\tomcatclpl"
Using CATALINA_HOME: "C:\Tomcat\tomcatclpl"
Using CATALINA_TMPDIR: "C:\Tomcat\tomcatclpl\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.6.0_01"
Using CLASSPATH: "C:\Tomcat\tomcatclpl\bin\bootstrap.jar"
C:\Tomcat\tomcatclpl>
This `bootstrap.jar file not started. Please help me out.
Because of the reason CATALINA_BASE & CATALINA_HOME taking same path
I couldn't to fixed this problem
I sort out the problem. First we should start the default tomcat server. Then only need to start instance servers
#echo off
#echo Tomcat CLPL Service
set "CATALINA_HOME=C:\Tomcat\apache-tomcat-6.0.35"
set "CATALINA_BASE=C:\Tomcat\tomcatclpl"
C:\Tomcat\apache-tomcat-6.0.35\bin\startup.bat
edit startup.bat
set CATALINA_BASE=..
set CATALINA_HOME=#catalina.home#
set CATALINA_OPTS=-server -Xms#jvm.minmemory#m -Xmx#jvm.maxmemory#m
"%CATALINA_HOME%\bin\catalina" run %1 %2 %3 %4 %5 %6 %7 %8 %9
More info can be found on Configuring Separate Instances Using CATALINA_BASE
#echo off
#echo Tomcat CLPL Service
set CATALINA_BASE="C:\Tomcat\tomcatclpl"
set CATALINA_HOME="C:\Tomcat\apache-tomcat-6.0.35"
C:\Tomcat\tomcatclpl\bin\startup.bat
This the way I normally sets the env variables
Let me fill this one out;
You unpack the tomcat zip twice, into two different folders
Go open commandpromt as administrator
navigate to 'tomcat1'\bin\
run service install tomcat1
navigate to 'tomcat2'\bin\
call on the commandline: set "CATALINA_HOME=C:\path\to\tomcat2\"
run service install tomcat2
Now you will see two services in your environment (the services.msc). Each called by the X being 1 or 2 as such: "Apache Tomcat tomcatX". They have the correct base/home variable and should point to the correct lib\ folder (thus bootstrap.jar is available to start the server with).
Problem is, the tool tomcat6w.exe with which you can control the service. It will only function (at least for me) with the default server, namely the first service installed. To bypass this and get the opportunity to define variables to the java environment, we need to find stuff with regedit.exe
Navigate the registry for: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\tomcat1\Parameters\Java
set Options / Xms / Xmx
figure out the rest (find tomcat2 in same tree)