Use nginx to complete reverse proxy and process static file requests

Source: Internet
Author: User
Tags nginx reverse proxy
: This article mainly introduces how to use nginx to complete reverse proxy and process static file requests. if you are interested in PHP tutorials, refer to it.

There are three main parts: nginx basic installation and use, reverse proxy and static file processing requests.

1. Installation and Use (windows)

First Download nginx from here and install it as needed. If you feel that English is a little difficult, you can take a look at the tutorial.

Start nginx
Method 1: run the command line to enter the nginx root directory and enter start nginx

Method 2: run the command line to enter the nginx root directory and enter nginx.exe.

Method 3: go to the nginxroot directory and double-click the nginx.exe icon.

I used Method 3 in the first place. it is really easy to run only one nginx instance on the machine, but I cannot figure it out when I need to run multiple nginx instances, therefore, Method 1 is recommended. The problem with Method 2 is that the cmd window is always in the execution state and cannot do other tasks.

Disable nginx

nginx.exe -s stopnginx.exe -s quit

The difference between the two is that stop is to stop nginx quickly, and does not save the relevant information; quit is to stop nginx in a complete and orderly manner, and save the relevant information.

Heavy load nginx

nginx.exe -s reload

After modifying the conf configuration file, restart the instance. If you close the process and then open it again, it is too troublesome, so you need to use heavy load.

Tips

Sometimes it cannot be started. At this time, you can go to logs/error. log to view the error message. I changed the listening port to 7000 in the conf file because port 80 is occupied by.

2. nginx Reverse proxy

An important role of nginx is to implement load balancing as a reverse proxy server. To implement this function, you need to modify the conf file.
Open conf/nginx. conf (we recommend that you use sublime and other editors to open it. try not to use notepad)

For more information, see the configuration file.

If you only implement the most basic reverse proxy function, no matter what the domain name is, send requests from this port to multiple backend servers. You can modify the configuration file in this way.

Http {......... upstream mysvr {server 127.0.0.1: 8002; # server 127.0.0.1: 8003; # server 127.0.0.1: 8004; # server 127.0.0.1; # data server intranet Port} server {listen 8001; # nginx listening port, is also the external port of three data servers server_name localhost; # charset KOI8-R; # access_log logs/host. access. log main; location/{# root/html; # index index.html index.htm; proxy_pass http: // mysvr; # for all domain names, use proxy_pass to reverse proxy to Port} in mysvr }.........}.........}

Add the mysvr item first, comment out the first two rows in the location/item, and add the proxy_pass option. Here I will send all requests from Port 8001 to ports 8004, and. After configuration, start the server first,

DataServer().listen(8002)DataServer().listen(8003)DataServer().listen(8004)

Start nginx, open the browser, and enter 127.0.0.1: 8001/auth, as shown below:

We can see that the request from Port 8001 is indeed sent to Port 8002 and other ports.

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above describes how to use nginx to complete reverse proxy and process static file requests, including some content, and hope to help friends who are interested in PHP tutorials.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.