Spring Boot and Nginx integration

前端 未结 1 1350
一个人的身影
一个人的身影 2021-02-02 04:01

In my project, web app is developed using Spring boot with default tomcat server. I am using NGINX as load-balancer and have configured my spring-boot-web-app in NGINX configura

相关标签:
1条回答
  • 2021-02-02 04:45

    This works for me. Can you try this?

    1. Running tomcat

      docker run -d -p 8080:8080 --name=tomcat tomcat:8 
      
    2. Running nginx

      docker run -d -p 80:80 --link tomcat:tomcat --name=nginx nginx
      
    3. Go inside nginx container and update the conf

      docker exec -it nginx bash
      

      /etc/nginx/nginx.conf:

      server {
         listen 80 default_server;
        server_name subdomain.domain.com;
        location / {
            proxy_pass http://tomcat:8080;
            proxy_set_header Host      $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
      }
      
    4. Restart nginx service

      nginx -s reload
      
    5. Access the tomcat through nginx from host browser. You may need to add entry to /etc/hosts

      http://subdomain.domain.com
      

    Complete nginx conf: nginx.conf

    0 讨论(0)
提交回复
热议问题