部署项目并设置为访问IP默认为该项目

问题:在工作中,昨天出现一个问题。公司需要的一个网站需要部署到服务器上,并映射到某域名上,即访问IP直接访问该项目。

解决方法

(1)tomcat解决

      ①、安装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文件找到<Host>标签,在其中添加

              此时访问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直接访问到自己的项目。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值