Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to reverse proxy Nginx to Tomcat server

Shulou Source: shulou.com Published: 2022-05-31 12:27:57 09月23日 Update

This article mainly introduces the relevant knowledge of Nginx how to reverse proxy to the Tomcat server, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe that everyone will gain something after reading this article on how to reverse proxy to the Tomcat server. Let's take a look.

In actual production, the tomcat server is generally not used alone in the project, and nginx performs well in response to static resources. In addition, because nginx is a server dedicated to reverse proxy, it is easy to forward the java request to the back end to the tomcat container for processing, and itself is used to handle static resources.

In nginx, a server {} block is often used to configure a larger project. Generally speaking, for all configurations of a domain name, there are multiple location in a server block to define multiple request rules, such as domain name and root directory configuration, static resource support, php fastcgi requests, url rewriting, error page configuration and other configurations, so the nginx proxy tomcat is the same as the previous forwarding php-fpm. Is to forward the request to the dynamic module at the back end to process the request.

Let's simply configure a location local rule in server to forward the specified nginx request to the tomcat container

Assuming that tomcat is running normally and the port number is 8080, first use vim to edit the nginx.conf configuration file, such as vim / usr/local/nginx/nginx.conf

Then at the end of the server {} block, add the following:

Location ^ ~ / tomcat/ {proxy_pass http://127.0.0.1:8080/; proxy_redirect off; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;}

After saving, reload the nginx configuration file: / usr/local/nginx/nginx-s reload

This is the end of the article on "how to reverse proxy Nginx to the Tomcat server". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to reverse proxy Nginx to Tomcat server". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Configuration server service agent multiple container resource static content domain name that is knowledge rules project processing file article support powerful balanced Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB NVidia vpn Apple