一、安装XAMPP及测试
①首先下载最新版本的XAMPP 1.7.7 for Windows
Apache 2.2.21
MySQL 5.5.16
PHP 5.3.8
phpMyAdmin 3.4.5
FileZilla FTP Server 0.9.39
Tomcat 7.0.21 (with mod_proxy_ajp as connector)
②安装或者解压下载文件。本机下载的是ZIP包,解压地址为:F:\xampp
打开XAMPP 所在的文件夹,并运行其中的“setup-xampp.bat”,然后点击“xampp-control.exe”。xampp1.7.7上已经整合了Tomcat7了,不用再去下载connector了,然后配置文件,省了不少时间。
③改配置文件为了避免端口冲突。
●F:\xampp\apache\conf\httpd.confListen 80
ServerName localhost:80
Listen 1109
ServerName localhost:1109
启动服务后访问地址:http://localhost:1109/xampp/
●F:\xampp\tomcat\conf\server.xml
<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />
<Connector port=”8009” protocol=”AJP/1.3″ redirectPort=”8443″ />
这两个地址都是可以访问的,因为已经整合到一起了。还有个端口8009这个要和httpd-ajp.conf文件一致。
http://localhost:8080/examples/
http://localhost:1109/examples/
Apache Tomcat页面→http://localhost:8080/
以上将localhost换成局域网IP地址,内网的机器都可以访问了。
二、导出Java工程到Tomcat,并配置文件允许其外网访问。
①导出工程为war文件。在Eclipse里面选中工程,File→Export。
将导出的包直接放到TOMCAT目录(F:\xampp\tomcat\webapps\)下就可以了。
②关键就是配置Apache AJP Proxy configuration这个文件httpd-ajp.conf。就是用代理模块mod_proxy实现了Apache的代理/网关。
●F:\xampp\apache\conf\extra\httpd-ajp.conf
默认:ProxyPass /examples ajp://127.0.0.1:8009/examples smax=0 ttl=60 retry=5
添加:ProxyPass /techpro ajp://127.0.0.1:8009/techpro smax=0 ttl=60 retry=5
类似于在server.xml里面加的Context。模块mod_proxy以及后面的参数意思可以查看官网
官网:http://httpd.apache.org/docs/2.2/en/mod/mod_proxy.html
中文翻译:http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_proxy.html
③设置路由器端口转发。各个路由器有所不同。(Google:路由器端口转发)
④查询本机的公网IP。(如果以下地址失效请Google:公网ip)
http://www.net.cn/static/customercare/yourIP.asp
⑤用公网IP访问项目。
http://公网IP:1109/examples/
http://公网IP:1109/techpro/