现在我一直在为此苦苦挣扎。 由于我是新的服务器安装的东西。 一直以来,在网上跟着很多教程和文档,很多都跑了,但是没有运气。
这是我到现在为止所做的。
我得到了我的VPS运行,它有Apache运行在80端口。
我在端口8080上安装了Tomcat 7.0.55,它已经启动并正在运行。
现在我们必须将stream量从Apache传送到Tomcat
以下
https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
修改apache的000-default.conf,看起来像这样。
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> <VirtualHost *:*> ProxyPreserveHost On # Servers to proxy the connection, or; # List of application servers: # Usage: # ProxyPass / http://[IP Addr.]:[port]/ # ProxyPassReverse / http://[IP Addr.]:[port]/ # Example: ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ ServerName localhost </VirtualHost>
这成功地将我的每个请求redirect到tomcat。
5现在我需要www.mytestdomain.com指向我的应用程序部署在$ CATALINA_HOME / webapps / www.mytestdomain.com
6和其他test.mytestdomain.com指向我的应用程序部署在$ CATALINA_HOME / webapps / test.mytestdomain.com
7和xx.xx.xx.xx我的ip只能登陆默认的tomcat页面。
那就是我想要达到的目标,而不是那个能力。
8下面
http://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.html
我更新了我的$ CATALINA_HOME / conf / server.xml,以便有一个主机。 更新我的server.xml文件的样子
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> <Host name="www.mytestdomain.com" appBase="webapps-new" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="www.mytestdomain.com_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
我创build了新的appBase目录mkdir $ CATALINA_HOME / webapps-new
在$ CATALINA_HOME / webapps-new文件夹中,我为我的webapp创build了符号链接。 ln -s ../webapp/www.mytestdomain.com ROOT
cd $ CATALINA_HOME / webapps-new / ROOT / WEB_INF /
在META-INF文件中创buildcontext.xml,内容如下。
重启Apache并重启Tomcat – [ok]
结果。 – >浏览器中的www.mytestdomain.com正确地打了我的tomcat webapp。
但是,我的浏览器test.mytestdomain.com和xx.xx.xx.xx我的IP也打我的同一个Web应用程序的www.mytestdomain.com。 他们应该已经去了默认主机。
我曾尝试过很多其他的技巧,但没有运气。
任何帮助,将不胜感激。 我知道这是非常可能的。
谢谢
这听起来相当复杂,而不是我试图运行的方式。
一般来说,我尽可能将环境分开,理想情况下运行在不同的服务器上,但我明白这不是一个单独的VPS所能做到的。
你应该至less分离tomcat实例,这将减less混乱,并使一切更清楚。
我会
1)在不同的端口上启动2个不同的tomcat实例(根据你正在运行哪个发行版以不同的方式实现),prod:8080和test:8180
2)在Apacheconfiguration中启用NameVirtualHost,并将正确的servername代理到正确的tomcat实例
# Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/example1 ServerName www.mytestdomain.com # Other directives here ProxyPreserveHost On ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost> <VirtualHost *:80> DocumentRoot /www/example2 ServerName test.mytestdomain.com # Other directives here ProxyPreserveHost On ProxyPass / http://localhost:8180/ ProxyPassReverse / http://localhost:8180/ </VirtualHost>
这样你的环境是完全独立的,你可以应用更改来testing,而不会影响prod,不只是在你的代码中,而且在tomcatconfiguration级别和apacheconfiguration级别。