Nginx and Apache with reverse proxy technology 2

Source: Internet
Author: User
Tags nginx server nginx reverse proxy

Note that last time we simply simulated a new HTTP server on the same server (8080 ports enabled), using Apache, which simulates the Nginx reverse proxy implemented by multiple servers, sending requests to the upstream proxy server via Nginx.

This time to the Nginx reverse proxy to make a specific configuration, according to "Mastering Nginx" recommended

First of all

sudo su//root mode

cd/etc/nginx/

Touch./proxy.conf//Create a separate proxy configuration

Vim./proxy.conf

As follows:

#Mastering nginx# off redirection proxy_redirect off; #传递给上游服务器用户头信息proxy_set_header Host $http _host;proxy_set_header X -real-IP $remote _addr;proxy_set_header X-forwarded-   the  4  32k;proxy_busy_buffers_size 64k; #控制worker进程阻塞后台数据的时间, the larger the value, the longer the processing blocking time Proxy_temp_file_write_ Size 64k;

And then

Vim./sites-available/default//Edit default site configuration file

Location ~ ^/Apache {        include proxy.conf;        Proxy_pass http://localhost:8080;    }

Service Nginx Reload//Reread Nginx

Note: If Nginx reload prompts failed, please check the/var/log/nginx/error.log error log!

Next, try to use the upstream server as the uploads directory, dedicated to storing the files uploaded by the user.

Vim/etc/nginx/sites-available/default

include proxy.conf; Location/uploads {client_max_body_size 500m; Proxy_connect_timeout the; Proxy_send_timeout -; Proxy_read_timeout -; Proxy_pass http://localhost:8080;} Location/{index index.htm index.html index.php; #如果文件不存在则尝试TP解析 #如果请求既不是一个文件, not a directory, execute the rewrite ruleif(!-e $request _filename)            {#地址作为将参数rewrite到index. php. Rewrite^/(. *) $/index.php/$1; }    }

Note that the proxy.conf is included outside the location and then internally overwritten with the original configuration, otherwise it will prompt "directive is duplicate".

Visit again: www.gxy.gift/uploads

Apache will proxy the access to the stored files

Next explain the use of try_files with the reverse proxy:

The role of this code is mentioned in the book "Mastering Nginx":

Location/ {        try_files $uri @apache;    }    Location @apache {        Proxy_pass http://localhost:8080;    }

This configuration is very simple, simply said: After the request sent to the Nginx server, according to the requested file or route live Nginx file, thereby rendering a static page, but if Nginx can not find such an address file or can not be routed, the address will be directly dropped to the upstream @apache

Summary: The so-called Web reverse Proxy service, to pay attention to proxy server use process is directly behind the domain name of this section of the request, that is, $uri sent to the upstream server, here is Apache, the equivalent of the user directly request the Apache server effect, If the Apache server is not able to handle this request, then the Apache not found prompt will be displayed.

Nginx and Apache with reverse proxy technology 2

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.