Nginx reverse proxy (not yet complete)

Source: Internet
Author: User
Tags nginx reverse proxy

Instance configuration: nginx reverse proxy:
Environment:
Vm1-nginx:
IP: eth0 172.16.3.2/16
Eth1 192.168.1.2/24
Vm2-apache + PHP + MYSQL:
IP: eth0 192.168.1.3/24
Vm3-apache:
IP: eth0 192.168.1.10/24

Test HOST: IP 172.16.20.109/16

1. vm1-nginx: configuration;


# Ifconfig eth0 172.16.3.2/16 up
# Ifconfig eth1 192.168.1.2/24 up
# Yum install nginx



# Cat/etc/nginx. conf
# User nobody;
Worker_processes 1;
Worker_rlimit_nofile 99999;

# Error_log logs/error. log;
# Error_log logs/error. Log notice;
# Error_log logs/error. Log Info;
Error_log/data/applogs/nginx/error. Log notice; defines the Error Log Level and storage path
# PID logs/nginx. PID;

Events {
Worker_connections 1024;
}

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;
Gzip on; enable the compression function
Gzip_http_version 1.0; defines the HTTP protocol version
Gzip_comp_level 2; defines the compression level
Gzip_types text/plain text/CSS application/X-JavaScript text/XML application/XML + RSS text/JavaScript Application/JSON; define the content in those formats to be compressed
Gzip_disable msie6; which browser does not perform compression?
Upstream webservers {defines the proxy's backend server group
Server 192.16.1.1 Weight = 2 max_fails = 2 fail_timeout = 3; Define backend-server1
Server 192.16.1.10 Weight = 1 max_fails = 2 fail_timeout = 3; Define backend-server2
Server 127.0.0.1: 8080 backup; defines the backup page server of the Local Machine
Least_conn; load balancing method, least_conn least connection
}

Server {VM www.hong.com
Listen 80 default_server;
SERVER_NAME www.hong.com;
Root/www/Ning;
Deny 172.16.3.3; Access to www.hong.com from 172.16.3.3 is denied.
Allow 172.16.0.0/16;
Deny all;
}
Server {
Listen 80;
SERVER_NAME www.ning.com;
Root/www/Ning;
Location/admin {User Authentication Mechanism
Auth_basic "Admin area"; prompt information for user verification
Auth_basic_user_file/etc/nginx/. htpasswd; Password Storage Method
}
Location/download/{define a download website
Autoindex on; Enable download website
Rewrite ^/download/(. * \. (JPG | GIF | JPEG | PNG) $/images/$1 break; Define the rewrite path
Rewrite_log on; Enable record re-write log
}
Location ~ * \. (JPG | PNG | GIF | JPG) $ {defines the anti-leech Function
Root/www/Ning;
Valid_referers none blocked www.ning.com * .ning.com; define rules that allow leeching
If ($ invalid_referer) {overwrite the definition that does not comply with the rule to that page
Rewrite ^/http://www.ning.com/403.html;
}
}
Location/Server-status {enable the sever: www.ning.com status Function
Stub_status on; Enable status detection
Access_log off; no access logs are recorded
Allow 172.16.20.109; allow access by 172.16.20.109 users
Deny all; reject all users
}

}
Server {define proxy content
Listen 80;
SERVER_NAME www.liang.com; specifies the name of the proxy server.
Location /{
Proxy_pass http: // webservers; specifies the proxy URL
Proxy_set_header X-real-IP $ remote_addr rewrite request message header information (add Client IP)
}
}
Server {specify the backup server
Listen 8080;
SERVER_NAME 127.0.0.1;
Root/www/htdocs;
}
}

 

# Service nginx start

 

2, vm2-apache + PHP + MYSQL: Configuration


# Ifconw.g eth0 192.168.1.3/24 up
# Yum install httpd PHP-mysql-y

# Mkdir/www/Ning-PV

# Vim/www/Ning/index. php

<? PHP

Phpinfo ();

? />

 

# Service httpd start

 

3, vm3-apache: Configuration

# Ifconfig eth0 192.168.1.10/24 up

# Yum install httpd

# Mkdir/www/Ning-PV

# Echo "192.168.1.10">/www/Ning/index.html

# Service httpd start

 

 

Test: http://www.ning.com (with the least connections set above)

Nginx reverse proxy (not yet complete)

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.