如何发布Web项目到互联网

如果我们有一个好的项目要发布到互联网上,我们首先需要购买域名以及主机,性能好(阿里云主机不错);

我们先在云主机上搭建环境,比如Mysql,Jdk,Tomcat;

然后我们把自己开发的项目打包,打成War包;

具体操作;右击项目-> Export

QQ鎴浘20160224184605.jpg

然后点击 Next ;

QQ鎴浘20160224184644.jpg


选择Browse,我们随便选个地方  然后点击Finish即可;

这样我们就可以生成一个War包了;

我们把War包传到主机上去,放到Tomcat的webapps下,启动tomcat的startup.bat,会自动解压项目;

到了这里,还不够。我们只能通过 http://外网IP:8080/项目名称访问;

我们现在要干两个事情,第一个是去掉端口,第二个是去掉项目名称

我们找到tomcat安装包下的conf文件夹下的server.xml文件;

QQ鎴浘20160224185006.jpg

找到Connector节点;

1
2
3
< Connector  port = "8080"  protocol = "HTTP/1.1"
                connectionTimeout = "20000"
                redirectPort = "8443"  />

我们把port="8080"改成80端口即可,这样我们就可以不用端口了。不加端口就是默认访问80端口;

我们在最后 找到Host节点:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
< 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 &quot;%r&quot; %s %b"  />
 
       </ Host >

我们在里面加一个节点:

<Context path="" docBase="C:\apache-tomcat-7.0.11-windows-x86\apache-tomcat-7.0.11\webapps\Blog" debug="0" reloadable="true" />   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
< 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" />
         -->
               < Context  path = ""  docBase = "C:\apache-tomcat-7.0.11-windows-x86\apache-tomcat-7.0.11\webapps\BaiduYun"  debug = "0"  reloadable = "true"  />   
         <!-- 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 &quot;%r&quot; %s %b"  resolveHosts = "false" />
 
       </ Host >

这里的docBase要给成你的项目所在你服务器的本机的绝对路径;

其他不用变;


项目数据库脚本的话自己导入下即可;这样就完整了项目部署;

我们可以直接通过外网IP直接访问项目;

域名解析下服务器外网IP。我们就可以通过域名访问了;



猜你喜欢

转载自blog.csdn.net/qq_21875331/article/details/78983960