Nginx 负载均衡动静分离配置
nginx.conf
1.通過目錄進行分離。
#靜態服務器
upstream static_pools
? {
????????? server 10.0.0.9:80 weight=5 max_fails=10 fail_timeout=10s;
????????????? }
#動態服務器
??? upstream dynamic_pools
????????????? {
????????? server 10.0.0.10:80 weight=5 max_fails=10 fail_timeout=10s;
?????????????????? }
#上傳服務器
??? upstream upload_pools????????????????????
{
????????? server 10.0.0.10:80 weight=5 max_fails=10 fail_timeout=10s;
?????????????????? }??????????
#server標簽配置:
server {
?????????? listen?? 80;
#訪問的域名
?????????? server_name www.xxxxx.com;
#動態服務器
???? location / {
?????????? proxy_pass http://dynamic_pools;
?????????? proxy_set_header Host??? $host;
?????????? proxy_set_header X-Forwarded-For $remote_addr;
???????????? }
#靜態服務器
? location /image/ {
?????????? proxy_pass http://static_pools;
?????????? proxy_set_header Host??? $host;
?????????? proxy_set_header X-Forwarded-For $remote_addr;
??????????????? }
#上傳服務器
? location /upload/ {
?????????? proxy_pass http://upload_pools;
?????????? proxy_set_header Host??? $host;
?????????? proxy_set_header X-Forwarded-For $remote_addr;
??????????????? }
? }
server {
?????????? listen?? 80;
#訪問的域名
?????????? server_name www.xxxxx.com;
#通過擴展名訪問
location ~ {
?????????? proxy_pass http://static_pools;
?????????? proxy_set_header Host??? $host;
?????????? proxy_set_header X-Forwarded-For $remote_addr;
??????????????? }
用于部分程序不支持的瀏覽器。
location /
{
#當使用IE瀏覽器時顯示動態內容
if ($http_user_agent ~* "MSIE")
{
proxy_pass http://dynamic_pools;
}
#當使用火狐瀏覽器時顯示靜態內容
if ($http_user_agent ~* "Firefox")
{
proxy_pass http://static_pools;
}
#其它使用默認
proxy_pass http://dynamic_pools;
include proxy.conf;
}
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
手機用戶和瀏覽器用戶:
當訪問同一個域名不同終端的時候,顯示內容的服務器不一致
location /
{
#當使用Android終端時訪問安卓服務器
if ($http_user_agent ~* "android")
{
proxy_pass http://android_pools;
}
#當使用蘋果終端時訪問蘋果服務器
if ($http_user_agent ~* "iphone")
{
proxy_pass http://iphone_pools;
}
#其它使用默認
proxy_pass http://dynamic_pools;
include proxy.conf;
}
轉載于:https://www.cnblogs.com/wangyifu/p/7202670.html
總結
以上是生活随笔為你收集整理的Nginx 负载均衡动静分离配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: winform 鼠标拖动移动图片位置
- 下一篇: php实现跑马灯闪亮,JavaScrip