1、安装nginx 详细步骤
http://www.xiaosongit.com/index/detail/id/64.html
2、apache安装
http://www.xiaosongit.com/index/detail/id/451.html
此反向代理及负载均衡思路来源于 https://www.cnblogs.com/ylbstu/articles/9717652.html
我们采用nginx 反向代理 到apache
1)nginx的反向代理:proxy_pass
2)nginx的负载均衡:upstream
第一步:先看nginx配置
nginx下配置的8068 http端口 会转向 8082 apache 服务器
server { listen 8068; client_max_body_size 100m; server_name localhost; access_log /usr/local/nginx/logs/8068-access.log main; error_log /usr/local/nginx/logs/8068-error.log; location / { proxy_pass http://172.28.66.194:8082; proxy_redirect off ; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 300; #跟后端服务器连接超时时间,发起握手等候响应时间 proxy_send_timeout 300; #后端服务器回传时间,就是在规定时间内后端服务器必须传完所有数据 proxy_read_timeout 600; #连接成功后等待后端服务器的响应时间,已经进入后端的排队之中等候处理 proxy_buffer_size 256k; #代理请求缓冲区,会保存用户的头信息以供nginx进行处理 proxy_buffers 4 256k; #同上,告诉nginx保存单个用几个buffer最大用多少空间 proxy_busy_buffers_size 256k; #如果系统很忙时候可以申请最大的proxy_buffers proxy_temp_file_write_size 256k; #proxy缓存临时文件的大小 proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; proxy_max_temp_file_size 128m; } }
apache配置文件:
Listen 8082 <VirtualHost *:8082> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/usr/local/apache/www/8082" DirectoryIndex index.php ServerName localhost:8082 #ServerAlias www.dummy-host.example.com ErrorLog "/usr/local/apache/www/8082/logs/dummy-error_log" CustomLog "/usr/local/apache/www/8082/logs/dummy-access_log" combined </VirtualHost>
ssl_certificate /data/ssl-key/guahao.cn.pem; ssl_certificate_key /data/ssl-key/guahao.cn.key; location ~ /video/ { proxy_pass http://10.20.120.156:9460; } location ~ /reservation/ { proxy_pass http://10.20.120.156:9458; } location ~ /servicepkg/ { proxy_pass http://10.20.97.113:9452; } location / { try_files $uri $uri/ /index.php?$query_string; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 3d; access_log off; }