Nginx+tomcat 通过域名访问项目

1.阿里云域名
http://www.tiexiaoer.top/
主机:47.94.11.55
Nginx+tomcat 通过域名访问项目
1.安装nginx

安装路径:/usr/softAdress/nginx/sbin

2.安装tomcat

3.修改nginx配置

http {
   
	   upstream tomcatserver {
	        server 47.94.11.55:8080; //换成你的公网ip
	  }
    server {
        listen       80;
        server_name  localhost;
       location / {
            ***proxy_pass   http://tomcatserver;***
            proxy_set_header        Host $host;
            proxy_set_header        X-Real-IP $remote_addr;
            index  index.html index.htm;
        }
保存后重新加载配置文件

cd /usr/softAdress/nginx/sbin

 ./nginx -s reload

4.修改tomcat配置

路径:vi  /usr/softAdress/tomcat/apache-tomcat-8.5.20/conf/server.xml
新增Context标签,替换docBase即可,tomcat路径+项目名


      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

       ***<Context path="" docBase="/usr/softAdress/tomcat/apache-tomcat-8.5.20/webapps/test" />***
        <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>
    </Engine>

5.浏览器访问

http://www.tiexiaoer.top/

Nginx+tomcat 通过域名访问项目