1. Preparation work
First you need a linux server, know the user name and password, and then you need to install it on a windows computer Install two tools that can connect to the Linux server, Xshell 5 and Xftp 5. I won’t go into the installation tutorial. The supplementary picture shows how to connect to the server:
The xshell connection interface is as follows, enter After confirming the host IP, click OK, and xshell will pop up a window to enter the user name and password to connect successfully!
You can understand it!
2. Installation and deployment work
To deploy the project to On a Linux server, it is essential to install jdk and tomcat. What I want to emphasize here is that if you want to deploy multiple applications on a server, you need to have its own tomcat for each application, because different Under the application, the configuration of tomcat is definitely different. In this case, you can install a tomcat installation directory and tomcat working directories under multiple applications. For the same parts, you can share the tomcat installation directory. The details will be introduced below. How to operate, how to install tomcat and jdk on your server
1. Directory division
This is A very important step is to create a new directory as shown in the figure below. Under this directory are placed some files related to project startup and deployment access. As you can see, I have placed multiple versions of jdk and multiple Version of tomcat, which tomcat and jdk are used during project deployment can be configured through configuration.
For actual applications, we specifically place them in an instance directory, establish the name of each application, and then place the corresponding war package, as well as the decompressed files, wait for tomcat to read the directory and deploy the application, as follows:
2 .Modify the configuration
We also place the tomcat under each application in a directory for easy management, as shown below, but you must pay attention to the configuration of each tomcat
Under the /bin directory, the start.sh file and stop.sh file must be modified. First, the jdk path must be specified, similar to configuring environment variables, and secondly That is, specify the tomcat path of the tomcat working directory. You can notice that CATALINA_HOME and CATALINA_BASE correspond to the installation directory and working directory of tomcat respectively. Then you can see from the last line that the project starts using start.sh under the installation directory. However, the tomcat configuration file used for project startup is the configuration file configured by each application tomcat. The same is true for stop.sh.
Permission is required to execute ./start.sh and ./stop.sh using xshell. If there is no permission, we can use xftp can modify the permissions of the start.sh email as shown in the figure and put a check mark.
Under the
/conf directory, you need to pay attention to the configuration modifications. The first is the server.xml file. Modify the corresponding port number and each application. Tomcat needs to modify different port numbers, otherwise the port will be occupied when starting multiple tomcats and cannot be started. It is best to remember the port number of tomcat configured for this application, which will be used later when using nginx for port mapping;
Another place to modify is the ROOT.xml file in the localhost directory under the Catalina directory. This file is used to specify which directory to load when tomcat starts. Project Example
Other /logs directory, /temp directory, /webapps directory, /work directory do not need to be modified; it can also be seen from the above , the directory division is very clear, divided into service installation directory (jdk, tomcat, nginx, etc.), application instance directory, and application deployment directory. You can also divide it in this way when using the Linux server to deploy multiple projects. .
3.nginx implements port 80 reverse proxy
Logically speaking, this At that time, we can transfer the war package of our own application to the corresponding directory and decompress it, and then go to the corresponding application tomcat working directory and execute ./start.sh to start the project! You might as well give it a try first.
After the project is deployed, we configure the hosts and start accessing it. At this time, we will find that we must add the tomcat port number configured above before we can access it. Can we not What about adding a port number (using the default port 80) for access? As mentioned above, we have configured different port numbers for different tomcats. The reason is that one port number can only be used by one tomcat. This means that project access must add port numbers for access. However, it must be done for each It is also possible for an application to use port 80 for access. This is when nginx is used. After installing nginx, we can add some configurations to achieve reverse proxy, and forward access to port 80 used by different applications to The corresponding port number. From the perspective of tomcat, external requests still use the port number configured by tomcat, which achieves the effect we want. The specific configuration is as follows (of course we also have to do the corresponding directory division work):
nginx directory is as follows:
We only need to care about the nginx.conf configuration file under the /conf directory , I also opened the specific configuration information for everyone to see. Did you notice the last line, "include domains/*", which means that the configuration is not complete yet and includes all configuration files in the /domains directory,
At this time, we can configure the corresponding nginx configuration of each application using files with different names.
Then let’s take a look at how to configure it. Listen for domain name access at auction.center.jd.net:80, and then forward it to the 1605 port of 127.0.0.1 of the local machine. We can also see from the configuration Yes, for some abnormal states, such as http_500 http_502 http_504, etc., they will be recorded and processed differently. Generally, you can jump to the homepage of the website, etc., and then record the log. After configuring this configuration file, we must not forget it. Create a new log directory, otherwise nginx cannot find the directory and will report an error when starting.
, if the restart fails, let's just take a tough step and kill the nginx process, and then use the nginx service start command to start the nginx service.
After we have completed these tasks, can we use the familiar method (without adding a port number) to access it? Yes, yes, that’s right, there are many People are worried about restarting tomcat and redeploying applications. It only means that you do not understand the nginx routing conversion layer of the network layer. The domain name we visit first performs DNS resolution through the hosts we configured and converts it to the corresponding IP. , find the server corresponding to the IP, go through the server's firewall, and then when we configure Nginx on the server, Nginx will first intercept the request, process and distribute the request, and finally hit the corresponding tomcat (personal understanding, maybe understanding It’s not in place yet, don’t spray it), at this time we can access the domain name with confidence and send requests! !
4. Step into the pit
Uh. . not good! ! I was overjoyed and jumped to the homepage, but still could not access the specified application. When I tried to add the port number, I was able to access it "miraculously". This means that the Nginx we configured did not take effect. What is the problem? ?
Now let’s talk about my problem-solving ideas. First, we have to confirm that all requests go to Nginx. At this time, the benefits of logs are reflected. When we use port 80 to access When we apply it, we stare at the log, twice, three times. . There is no log. At this time, we can roughly conclude that the Nginx service has not been used at all. We cannot be sure that the nginx service has not taken effect on the server. Maybe there is a problem with our log configuration. At this time, I made a bold operation. That is to turn off the nginx service access, or jump to the homepage of the website. What's going on? Isn't jumping to the homepage configured through nginx? Indeed, the company has already dealt with it at the network layer. At this time, I was very confused. I just tried various attempts. I might as well modify the tomcat configuration and configure one of the applications to port 80, so that it can always be accessed. Soon, the modification was completed. After deploying it, just wait for the domain name to be entered in the address bar to access it. Because the Nginx service has been shut down, the request at this time must be directly sent to tomcat. The access is once, twice and three times. Miraculously, it cannot be accessed. Na Ni? ? ? At this time, I had a flash of inspiration. The server firewall must have disabled port 80. I quickly tried to telnet 192.168.108.37 80 locally and it turned out that I couldn't access it. This proved that my guess was correct. It was easy to handle now. I just needed to enable it in the firewall. Access to port 80 is enough. Let’s add how to configure the iptables firewall to open port 80 under CentOS.
1. Open the configuration file of iptables, the code is as follows: vi /etc/sysconfig/iptables
2. Through /etc/init. d/iptables status, command to query whether port 80 is open. If not, there are two ways to handle it
3. The first way: modify the vi /etc/sysconfig/iptables command to add Make the firewall open port 80, the code is as follows:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
4. The code to close/enable/restart the firewall is as follows:/etc/init.d/iptables stop (# start, #restart restart)
5. The second way: add the port through the command, the code is as follows:
[root@centos httpd]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT [root@centos httpd]# /etc/rc.d/init.d/iptables save [root@centos httpd]# /etc/init.d/iptables restart
6. Check the effect: [root@centos httpd]# /etc/init.d/iptables status
7. In addition, it is recommended to use the second method, operation Simple and high success rate. Take me as an example. When I use the first method to modify the firewall configuration, the restart fails. When I use the second method, it succeeds perfectly.
三、Summary
The final result is also expected. Even if tomcat is configured with port 1605, we can still use port 80 to access it. This is The power of nginx, just a few megabytes of installation package, can actually play so many roles. I just started to learn nginx, and my understanding is very rudimentary, but through this practice, I have a good impression of nginx, and slowly I will get to know each other from acquaintance (although we cannot know each other and love each other).
The above is the detailed content of Server deployment of tomcat and Nginx. For more information, please follow other related articles on the PHP Chinese website!

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools