nginx的读写分离
一般网站都是用rsync+inotify实现文件同步,而rsync+inotify并不能双向同步,所以这个时候我们就要使用到读写分离。拓扑:nginx:192.168.137.50:80后端web:apache1:192.168.137.51:80
apache2:192.168.137.52:80
这里我们使用nginx作为反向代理,使用if语句和$request_method模块实现读写分离,
配置如下:
server {
listen 80;
server_namelocalhost;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
proxy_pass http://192.168.137.51/;
if ( $request_method = "PUT"){
proxy_pass http://192.168.137.52;
}
indexindex.html index.htm;
}
当$request_method为PUT,我们将请求转发给只做写的web端。
重启nginx,使用curl测试:
# curl http://192.168.137.50
2.syk.com
# curl http://192.168.137.50
2.syk.com
# curl http://192.168.137.50
2.syk.com
# curl http://192.168.137.50
2.syk.com
读取只被转发到了192.168.137.51端;
开启192.168.137.52端apache的上传模块:
vim /etc/httpd/conf/httpd.conf
在下添加:
dav on即可
测试: # curl -T /etc/passwd http://192.168.137.50
403 Forbidden
Forbidden
You don't have permission to access /passwd
on this server.
Apache/2.2.15 (CentOS) Server at 192.168.137.52 Port 80
出现403,是因为apache目录属组为root,所以这里做修改:
setfacl -m u:apache:rwx /var/www/html/
再次测试:
# curl -T /etc/passwd http://192.168.137.50
201 Created
Created
Resource /passwd has been created.
Apache/2.2.15 (CentOS) Server at 192.168.137.52 Port 80
并且我们可以看到,文件被上传到了192.168.137.52端。
页:
[1]