Nginx Read-Write separation

Source: Internet
Author: User
Tags inotify

The general website is used rsync+inotify enables file synchronization, whileRsync+inotify does not synchronize in two directions, so this time we are going to use the read and write separation. topology: Nginx:192.168.137.50:80
back-end web:apache1:192.168.137.51:80
                           apache2:192.168.137.52:80
Here we use Nginx as the reverse proxy, using the IFstatements, and$request _method Module for read-write separation,
The configuration is as follows:

server {

Listen 80;

server_name localhost;

#charset Koi8-r;

#access_log Logs/host.access.log Main;

Location/{

Proxy_pass http://192.168.137.51/;

if ($request _method = "PUT") {

Proxy_pass http://192.168.137.52;

}

Index index.html index.htm;

}

when$request _method is put, we forward the request to a write-only web side.

to restart Nginx, use Curl test:

[Email protected] conf]# Curl http://192.168.137.50

[Email protected] conf]# Curl http://192.168.137.50

[Email protected] conf]# Curl http://192.168.137.50

[Email protected] conf]# Curl http://192.168.137.50

the read was forwarded only to the 192.168.137.51 end;



Open the 192.168.137.52-side Apache upload module:

Vim/etc/httpd/conf/httpd.conf

Added under <directory "/var/www/html" >:

DAV on Can


Test:


[Email protected] conf]# curl-t/etc/passwd http://192.168.137.50

<! DOCTYPE HTML PUBLIC "-//ietf//dtd HTML 2.0//en" >

<title>403 forbidden</title>

<p>you don ' t has permission to ACCESS/PASSWD

On this server.</p>

<address>apache/2.2.15 (CentOS) Server at 192.168.137.52 Port 80</address>

</body>

403 occurs because the Apache directory belongs to the group root, so here are the modifications:

Setfacl-m u:apache:rwx/var/www/html/


Test again:

[Email protected] conf]# curl-t/etc/passwd http://192.168.137.50

<! DOCTYPE HTML PUBLIC "-//ietf//dtd HTML 2.0//en" >

<title>201 created</title>

<P>RESOURCE/PASSWD has been created.</p>

<address>apache/2.2.15 (CentOS) Server at 192.168.137.52 Port 80</address>

</body>

and we can see that the file was uploaded to the 192.168.137.52 end.

This article is from the "Linux" blog, so be sure to keep this source http://syklinux.blog.51cto.com/9631548/1837046

Nginx Read-Write separation

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.