若转载此文请注明出处。谢谢。
//注:linux用rz命令上传文件:压缩包文件名称不能保函中文和特殊符号,全部改为英文后再传。
【以下操作:已实践并成功。】
一、注册域名。如:youproject.com
二、购买服务器。最少3个月。公网如:101.31.1.110
三、备案域名成功。(若未备案先用101.31.1.110访问)
四、设置您的项目:
1、文件夹youproject下(例如有):
index.html、(首页)
page1.html、
page2.html、
...
js
css
images
....
WEB-INF (相关配置文件)
(前提:
linux安装
1、jdk8:https://blog.csdn.net/xysxlgq/article/details/122802728 ;
2、tomcat: https://blog.csdn.net/xysxlgq/article/details/122802706 ;
3、linux基础命令:
4、用户设置:https://blog.csdn.net/xysxlgq/article/details/119879703 、
5、linux上传下载文件:https://blog.csdn.net/xysxlgq/article/details/121595920 、
6、看文件大小:https://blog.csdn.net/xysxlgq/article/details/121595947、
7、rar解压缩:https://blog.csdn.net/xysxlgq/article/details/121566222、
8、编辑命令:https://blog.csdn.net/xysxlgq/article/details/121564960
)
2、把youproject文件夹添加到:/tomcat/apache-tomcat-8.5.75/webapps中(其他文件不动):文件结构:
drwxr-x--- x root root xxxx Mar xx 23:57 docs/
drwxr-x--- x root root xxxx Mar xx 23:57 examples/
drwxr-x--- x root root xxxx Mar xx 23:57 host-manager/
drwxr-x--- x root root xxxx Mar xx 23:57 manager/
drwxr-x--- x root root xxxx Mar xx 23:57 ROOT/
drwxr-xr-x x root root xxxx Mar xx 10:32 youproject/
(数字用xx代替了)
3、用txt工具打开 WEB-INF 文件夹下的 web.xml 中加入:(首页配置)
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
配置后为:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
五、tomcat 相关配置:
1、cd /tomcat/apache-tomcat-8.5.75/conf 后 vim server.xml
把8080改为80端口:
原始:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" />
改后:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" />
2、最底部 </Host> 结尾的上一行中插入:
<Context docBase="youproject" path="/" reloadable="true" />
原始:
<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="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" />
<Context docBase="youproject" path="/" reloadable="true" />
</Host>
其他不动,esc :wq!
启动tomcat服务:
cd ../bin
./startup.sh
六、浏览器输入:101.31.1.110 即可看到自己的项目。
七、域名访问:(云服务商官网配置)
1、域名备案成功。
2、域名解析ip(101.31.1.110)
3、开启安全策略和80端口。
4、在浏览器输入域名,即可看到网站。
若转载此文请注明出处。谢谢。
若对您有用请关注点赞收藏。有问题请留言。谢谢。