①、安装tomcat
yum install tomcat -y #yum安装tomcat yum install tomcat-webapps tomcat-admin-webapps -y #安装验证页面
②、启动tomcat,并设置为开机自启动
[root@localhost ~]# systemctl start tomcat [root@localhost ~]# systemctl enable tomcat Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.
③、访问页面,出现默认页面
④、将自己目前得项目上传到/usr/share/tomcat/webapps/之下
目前访问自己的项目需要访问http://IP:8080/项目名
⑤、设置访问为默认项目
方法:打开/etc/tomcat/server.xml文件找到
此时访问http://IP:8080就可以访问自己的项目。
⑥、设置访问IP直接访问该项目
方法一:修改server.xml中的端口号。(注:该方法我自己实验未成功)
方法二:利用firewalld进行转发
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent #开放80端口 success [root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent #开放8080端口 success [root@localhost ~]# firewall-cmd --add-masquerade --permanent #允许防火墙伪装ip success [root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 --permanent #将80端口的流量转发至8080 success [root@localhost ~]# firewall-cmd --reload #重启生效 success
此时访问http://IP就可以访问自己的项目。
(2)nginx解决①、安装nginx
新建/etc/yum.repos.d/nginx.repo [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key 下载nginx yum install nginx 启动nginx systemctl start nginx
此时访问页面出现nginx默认页面
②、设置访问项目
将自己的项目放置到/usr/share/nginx/html/下
此时访问http://IP/项目名可访问自己的项目
③、设置为默认访问项目
重启nginx,此时就可以访问IP直接访问到自己的项目。



