Windows installation nginx, nginx download and installation tutorial

Windows安装nginx,nginx下载与安装教程

How to install nginx under Windows

a lot of familiarityhave been used by, nginx as webIt takes up less resources and has powerful functions. This small and powerful nginx is slowly devouring the same web server.and IIS share. So what are the powerful functions of nginx? In addition to the functions of the web server, many people may not understand the truly powerful functions of nginx.

nginx, Apache, and iis are collectively called the three swordsmen of the web server.

nginx [engine x] is HTTP and reverse,mailserver and generic TCP/UDP proxy server, originally developed byIgor Sysoevwrite. For a long time it has been under many heavy loadsrun on the website, including YandexMail.RuVKand Rambler. According to Netcraft data, nginx served or proxied 21.79% of the busiest sites in April 2022. Here are some success stories: DropboxNetflixWordPress.com, FastMail.FM.

used for The nginx version uses the native Win32 API (not the Cygwin emulation layer). Currently only the select() and poll() (1.15.9) connection handling methods are used, so high performance and scalability should not be expected. Due to this and some other known issues, the Windows version of nginx is considered a beta release. Currently, it provides almost the same functionality as the UNIX version of nginx, except for XSLT filters, image filters, GeoIP modules, and embedded Perl language.

What is a reverse proxy?

nginx can not only provide the basic functions of the web server, but also the excellent reverse proxy function is also very powerful. Reverse proxy (Reverse proxy) ) method refers to using a proxy server to acceptThe connection request is made on the Internet, and then the request is forwarded to the server on the internal network, and the result obtained from the server is returned to the client requesting the connection on the Internet. At this time, the proxy server appears as a server to the outside world.

Download nginx

First visit the official website of nginx, which provides the Windows version of nginx server-side software.

Visit ngixn official website:https://nginx.org/

Windows安装nginx,nginx下载与安装教程

As of 2022, the latest version is nginx-1.21.6. Click to download on the right and download the Windows version of nginx on the download page.

Windows安装nginx,nginx下载与安装教程

You can choose to download the mainline version or download the stable version.

click to download:nginx/Windows-1.21.6 | nginx/Windows-1.20.2 

Install nginx

After downloading, double-click the nginx.exe file to run nginx.

Windows安装nginx,nginx下载与安装教程

After double-clicking nginx.exe, a black pop-up window flashed by, indicating that nginx had started successfully.

Or open the cmd command window, switch to the nginx decompression directory, enter the command nginx.exe or start nginx, and press Enter to open nginx.

How to check whether nginx starts successfully? Enter in browser http://localhost 

Windows安装nginx,nginx下载与安装教程

If you can see the welcome page of nginx, congratulations, it has been started successfully.

Configure nginx

nginx has been installed successfully. Next, you need to configure nginx. Like Linux, nginx in Windows also needs to modify the nginx configuration file to configure nginx.

Click to open CONF Folder, use notepad to edit within the folder document

http{
server{
listen 80; # listening port, change this when configuring based on IP, such as 192.168.1.100:8080;
server_name www.uzbox.com;
# host domain name. If the actual project is released, fill in the domain name on the public network. If deployed locally, you can add the mapping of IP and domain name in the C:\Windows\System32\drivers\etc\hosts file.
# mapping analysis, / represents the root path, and there is also a regular expression analysis method here.
location/{
root E:/uzbox; # website path
index index.html index.htm; # homepage file
}
}
}

When setting the directory where the website is located, use / instead of \.

Some common configurations in http{}

include mime.types; # file extension and file type mapping table
default_type application/octet-stream; # default file type
# turns on the efficient file transfer mode. The sendfile instruction specifies whether nginx calls the sendfile function to output files. It is set to on for ordinary applications. If it is used for disk IO heavy load applications such as downloading, it can be set to off to balance disk and network I. /O processing speed and reduce system load. Note: If the image does not display properly, change this to off.
autoindex on; # turns on directory list access, suitable for downloading servers, and is turned off by default.
tcp_nopush on; # prevents network congestion
tcp_nodelay on; # prevents network congestion
keepalive_timeout 120; # long connection timeout, unit is seconds
gzip on; # turns on gzip compression output

After the nginx.conf file is configured, use the following command to check whether the configuration file is correct.

nginx -t

After entering the command, if the configuration is correct, syntax is ok will be returned. If it is wrong, the wrong line will be returned.

If you use the default port 80, first check whether the port setting in the nginx.conf configuration file in the conf directory is 80. After confirmation, use the following command to check whether port 80 is available.

netstat -ano | findstr 0.0.0.0:80

Windows安装nginx,nginx下载与安装教程

Or use the following port detection command:

netstat -ano | findstr "80"

Windows安装nginx,nginx下载与安装教程

When you modify the nginx configuration file nginx.conf, you do not need to shut down nginx and restart nginx. You only need to execute the following command to make the changes take effect.

nginx -s reload

If you want to shut down nginx

Enter the nginx command in the CMD window

nginx -s stop

or

nginx -s quit

nginx configure reverse proxy

Add the tomcat_server block in the nginx.conf configuration file, and fill in the domain name of the website that requires proxying in the tomcat_server block.

#upstream tomcat_server blocks reverse proxy settings.
upstream tomcat_server{
server t1.uzbox.com;
}

If you need to configure load balancing in a reverse proxy, you can configure multiple reverse proxy websites.

# load balancing website configuration core block
upstream tomcat_server{
server t1.uzbox.com weight=1;
server t2.uzbox.com weight=2;
}

Weight attribute, this attribute indicates the weight of each server being accessed. The higher the weight, the higher the probability of being accessed. For example, if weight=2, nginx has priority to access t2.uzbox.com. When there are too many users accessing t2.uzbox.com, it will automatically switch to t1.uzbox.com.

After setting up the tomcat_server block above, set up the reverse proxy in the server block.

server {
location/{
proxy_pass http://tomcat_server;
# is in the root directory and uses proxy_pass to call the tomcat_server block.
}
}
After the configuration is complete, use nginx -t to check whether the syntax is correct, and finally restart nginx

nginx -s reload

Conclusion

Under WindowsIt has been successful. The configuration method under Windows is similar to that under Linux. There is no difference. The only problem is the difference in the root web storage directory. When calling a directory, use / instead of \.

nginx -s stop quick shutdown
nginx -s quit graceful shutdown
nginx -s reload changes the configuration, starts a new worker process with the new configuration, and shuts down the old worker process gracefully
nginx -s reopen reopens the log file

Known issues

Although several workers can be started, only one worker is actually doing any work.
UDP proxy functionality is not supported.

Possible future enhancements

Run as a service.
Use I/O completion ports as the connection handling method.
Use multiple worker threads in a single worker process.

score

Leave a Reply

Your email address will not be published. Required fields are marked *