Introduction to Nginx
Nginx is a free, open source, high-performanceHTTP serverandreverse proxy server; It is also an IMAP, POP3, SMTP proxy server; Nginx can be used as an HTTP server to publish the website, and Nginx can be used as a reverse proxy to implement load balancing.
- Nginx uses an event-driven architecture that enables it to support millions of TCP connections
- A high degree of modularization and free software licenses make third-party modules emerge in an endless stream (open source)
- Nginx is a cross-platform server that can run on Linux, Windows, FreeBSD, Solaris, AIX, Mac OS and other operating systems
- Very high stability
1. Install Nginx to realize double-click startup and double-click shutdown
1. Download Nginx
Official download address: http://nginx.org/en/download.html
Choose any windows version
2. After getting the installation package, just put it in a directory you like, and enter the directory
3. Double-click to start, double-click to close
3.1. Double-click to start, and click the nginx.exe file.
3.2. Double click to close
3.2.1. Create a 关闭nginx.txt
file named and writetaskkill /f /t /im nginx.exe
3.2.2. Change the suffix of the file to 关闭nginx.bat
a file
3.3. Create a shortcut and put it on the desktop
4. Test
4.1. Double-click the nginx.exe file
4.2. The address accessed by the browser localhost
, as shown below, proves that nginx started successfully
4.3. Close nginx, double-click 关闭nginx.bat
the file, and refresh localhost
the page. The following display proves that nginx is closed successfully
2. Configure load balancing and test
1. Open conf
the directory undernginx.conf
2. Modify nginx.conf
the file
In fact, I just added the code of upstream server_list
and proxy_pass
, and the others are all included in this configuration file. The following is all the code of my entire nginx.conf
file
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 负载均衡配置访问路径 serverList名字随便取
upstream serverList{
# 这个是tomcat的访问路径
server localhost:8080;
server localhost:9090;
}
server {
listen 80;
server_name localhost;
location / {
root html;
proxy_pass http://serverList;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3. Use the jmeter tool to test
For students who don’t know how to use it jmeter
, you can read this article of mine: jmeter installation and use, full picture and text explanation_I Can’t Recognize Your Blog-CSDN Blog
Students who will not start two identical projects with different ports at the same time can read this article of mine: idea to start two projects with the same service but different ports at the same time, full diagram_I Can’t Recognize Your Blog-CSDN Blog
3.1. Double-click to start the nginx.exe file
3.2. Start two springboot projects: idea implements two projects with the same service but different ports at the same time
3.3, configure jmeter: jmeter installation and use, full picture and text explanation
3.5. Check the springboot console output information
3.5.1, port 8080
We can see that nginx
by default, polling is used to achieve load balancing, and we can see that there are ten pieces of data under port 8080
3.5.2, 9090 port
There are also ten pieces of data under the port 9090