Nginx is simply deployed to implement the reverse proxy function, and comes with a resource package

WBOY
Release: 2016-07-28 08:26:41
Original
1031 people have browsed it

1. Download nginx from the official website, URL:http://nginx.org
You can also click here to download: nginx resource download

2. Basic nginx commands

Open cmd and switch to the nginx path, as shown below:

Nginx简单部署实现反向代理的功能,附带资源包

Enter start nginx and press Enter and the window will flash by. According to past experience, compatriots must have made mistakes in the past. In fact, they are not. You can go to the task manager to see if there are more processes similar to nginx, as shown below

Nginx简单部署实现反向代理的功能,附带资源包

Nginx简单部署实现反向代理的功能,附带资源包

Now we have started nginx, don’t worry at this time To do request forwarding (reverse proxy), we first open the browser and enterhttp://localhostto see the page results returned by the browser as follows:

Nginx简单部署实现反向代理的功能,附带资源包

At this time, you can see that nginx has started successfully. Now visit is the page in the nginx directory, so how to achieve the effect of reverse proxy? At this time, open the nginx file directory again. There are many configuration files under the conf folder. At this time, we only need to change a file named: nginx.conf. Use a text editor to open this file and you can see the following configuration. , only the server part is intercepted:

Nginx简单部署实现反向代理的功能,附带资源包

This code is equivalent to a proxy server, and multiple ones can also be configured. The following mainly introduces the meaning of the main parameters in the server:

listen: Indicates the port that the current proxy server listens to , the default is port 80, you can also write other port numbers. Note that when configuring multiple servers, this port cannot be written the same. In addition, do not mistake this port for your own tomcat port. The port here is http request port.

server_name: Indicates where to redirect after listening. We will redirect this to tomcat as an example later.

location: indicates the matching path, / indicates matching all requests.

Now let’s modify the corresponding configuration parameters so that when requesting localhost, it will redirect to the tomcat homepage. The modified configuration is as follows:

Nginx简单部署实现反向代理的功能,附带资源包

After modifying the configuration, you need to reload the configuration file. At this time, execute it in the cmd window just now nginx -s
reload (nginx -s
stop is to stop the nginx service), and then open the browser to visithttp://localhostYou can see that the result is no longer the nginx homepage, but the tomcat homepage, as shown below:

Nginx简单部署实现反向代理的功能,附带资源包

The above is the simple implementation of nginx The process of reverse proxy can also implement type filtering and forwarding, that is, different requests are directed to different destinations. I will not introduce it in detail here. nginx is very powerful. If there are any errors, please point them out and make progress together; my hands are tired and twitching. , please note the source when reprinting!

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the simple deployment of Nginx to implement the reverse proxy function. It comes with a resource package, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!