Edit application path when using AWS Elastic Beans

2019-08-23 21:00发布

问题:

With local tomcat my application url is: http://ip:port/myapp but when deploying it to AWS Elastic Beanstalk the url becomes http://some_domain.com. I want the url to be http://some_domain.com/myapp.

How do I do that? I found something about adding some config file to .ebextensions but I wasn't sure what exactly I should do and whether it helps at all.

UPDATE:

I created an .ebextensions folder and put the the following files:

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
    <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
    <Listener className="org.apache.catalina.core.JasperListener"/>
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
    <GlobalNamingResources>
        <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
    </GlobalNamingResources>
    <Service name="Catalina">
        <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
        <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
        <Engine defaultHost="localhost" name="Catalina">
            <Realm className="org.apache.catalina.realm.LockOutRealm">
                <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
            </Realm>
            <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
                <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
                <Context docBase="EizeRest" path="/EizeRest" reloadable="true" source="org.eclipse.jst.jee.server:EizeRest"/>
            </Host>
        </Engine>
    </Service>
</Server>

server-update.config

container_commands: 
  replace-config: 
    command: cp .ebextensions/server.xml /etc/tomcat7/server.xml 

And when deploying I'm getting the following error:

"aws Unable to detect application deployment"

Here is a screenshot:

Another update:

I see in the events tab of the server the following error: cannot stat '.ebextensions/server.xml': No such file or directory

回答1:

I believe you will need to take the following steps:

  1. create a Tomcat server.xml file that sets path=myapp
  2. copy this file to beanstalk during its deployment phase

Beanstalk documentation provides a relevant guide for that here: http://aws.typepad.com/aws/2012/10/customize-elastic-beanstalk-using-configuration-files.html

Basically the guide says you need to copy the server.xml to beanstalk by creating the following file in your application root: .ebextenstions/tomcat.config:

container_commands: 
  replace-config: 
    command: cp .ebextensions/server.xml /etc/tomcat7/server.xml 

don't forget to commit both the server.xml and the tomcat.config files in the .ebextensions folder.



回答2:

You must place your ".ebextensions" folder at the same level as your WEB-INF folder. Doing that will remove the ".ebextensions/server.xml: No such file or directory" error.