09-ngx_http_proxy_module Module

Source: Internet
Author: User
Tags response code nginx server

Ngx_http_proxy_module Module Common directives:

1, Proxy_pass URL;    This instruction is used to set the protocol, host name, IP address, and port of the proxy server.
2 , proxy_set_header field value;    Sets the value of the request header for the request message of the backend host;     field: the header field where you want to change the information value    : Changed values that support the use of text, variables, or combinations of variables    proxy_set_header X-real- IP  $remote _addr;     Proxy_set_header X
3 , Proxy_cache_path    defines the cache that can be used for the proxy function;    proxy_cache_path path [levels=levels] [Use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size]    ... Levels: Sets the cache index for cached data in the first-order hash directory of the path-specified directory     Key_zone:nginx server The simple process indexes the cached data in memory to define the name and size     of the memory area in which the cache index is stored Inactive; Indicates cache valid time    max_size: Set large size of cache data on hard disk
4, Proxy_cache Zone | Off;    Indicates the cache to invoke, or closes the caching mechanism;
5 string ; The contents of the cache for "keys"    ;
6 time;    Defines the cache duration for the response content of a specific response code;
7. Proxy_cache_use_stale     using expired cache
8, Proxy_cache_methods GET | HEAD | POST ...;     
9, proxy_hide_header field;     This instruction is used to set the Nginx server to hide some header information when sending a response message.
Ten time;    
 One time;    
 A time;    This directive sets the timeout for waiting for a response after the Nginx server has issued a write request to the proxy server back end  

Ngx_http_headers_module: The module adds a custom header to the response message that the proxy server responds to the client, or modifies the value of the header.

1 , Add_header name value [always];     Add a custom header;     add_header X-Via  $server _addr;     Add_header X
2 time;    Expires Epoch | Max | Off     

Small experiment: Configure the reverse proxy Server Lnamp and verify the caching capabilities

Each node is centos7.2, where controller1 node installation nginx Implementation reverse proxy, controller2 node installation Httpd,php,wordpress,controller3 installation mariadb.

First the Controller3 node installs the MARIADB, creates the database WordPress and authorizes to the Carl user

MariaDB [(None)]> create database WordPress; MariaDB [(none)]'Carl'@'%'jl3040265  '; MariaDB [(None)]> Flush privileges;

Controller2 node Install Httpd,php,php-mysql, and configure the environment for WordPress

Yum install httpd php php-mysql1. Modify HTTPD Master profile servername to www.mywordpress2 Unzip WordPress to/var/www/HTML directory 3. Switch to WordPress directory,CP wp-config-sample.php wp-  config.php4. Configure wp-config.php to start WordPress

Controller1 node Installation nginx, configure reverse proxy function

Add the cache configuration information in the HTTP configuration section of the Nginx master configuration    file Proxy_cache_path /var/nginx      levels=1:2  keys_zone=proxycache:20m max_size=mkdir -PV/ var/nginx Configuring virtual machine Reverse Proxy

server {        a;        server_name     www.test.com;        Location        /WordPress  {                proxy_pass      http://9.110.187.121:80/;                 proxy_cache     proxycache;                Proxy_cache_key $request _uri;                Proxy_cache_methods     GET HEAD;                Proxy_cache_valid       302  20m;                Proxy_cache_valid       404     5m;        }}

Access www.test.com can see the effect, Ls/var/nginx can see the cached file.

09-ngx_http_proxy_module Module

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.