Nginx Reverse proxy configuration

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

Beta version nginx1.6.3

Test System: CentOS 6 System

Installation Configuration document: http://jasonzhu.blog.51cto.com/5594807/1750188


Principle:

The user makes the access request, the domain name resolves to the nginx server's IP (23.234.xx.2), configures the IP reverse proxy in the Nginx server, will xx.2 receives the request, through the proxy forwarding rule, all transfers to 23.234.xx.3


User---(Request, domain name resolution IP)---> Anti-attack (nginx forwarding server)---(proxy forwarding rule)---backend Apache server


IP Reverse proxy configuration:

Vim/usr/local/nginx/conf/nginx.conf

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

#log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '

# ' $status $body _bytes_sent ' $http _referer '

# ' "$http _user_agent" "$http _x_forwarded_for" ';

#access_log Logs/access.log Main;

Sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

Keepalive_timeout 65;

#gzip on;

include/usr/local/nginx/conf/conf.d/*.conf;

server {

Listen 80;

server_name _;

#charset Koi8-r;

#access_log Logs/host.access.log Main;

Location/{

Proxy_next_upstream http_502 http_504 error timeout invalid_header;

Proxy_pass http:/$target;

Proxy_set_header Host $host;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

}

#error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html

#

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}


Create conf.d/map.conf extended forwarding rules under the/usr/local/nginx/conf/directory

Vim/usr/local/nginx/conf/conf.d/map.conf

Map $server _addr $target {

#baidu. com

23.234.xx.2 23.234.xx.3:80;

#请求IP Forwarding IP: Port

}

The Ps:target parameter is passed to the nginx.conf configuration file as the address of the next hop forwarding.


/usr/local/nginx/sbin/nginx-s Reload Reload configuration file


Nginx Reverse proxy configuration

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.