部署分佈式存儲系統FastDFS(續一)

因字數限制,新開文章javascript

第九天css

今天設置nginx代理,代理存儲服務的http訪問。html

在沒有代理前,咱們上傳了圖片,須要使用group中的任一storage server進行訪問,若是是多group,很麻煩。java

新增一臺虛擬機,部署nginx環境,參考網上教程。nginx

nginx配置文件以下(包含了簡單的防盜鏈功能):web

user www-data;後端

worker_processes 4;服務器

pid /run/nginx.pid;app


events {tcp

worker_connections 768;

# multi_accept on;

}


http {

include mime.types;

default_type application/octet-stream;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 300m;

sendfile on;

tcp_nopush on;

keepalive_timeout 120;

gzip on;

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types text/plain applicatin/x-javascript text/css application/xml;

gzip_vary on;

gzip_disable "MSIE[1-6]."

proxy_redirect off;

#當後端單臺web服務器上配置有多個虛擬主機時,須要使用該Header來區分反向代理哪一個主機名

proxy_set_header Host $http_host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffer_size 16k;

proxy_buffers 4 64k;

proxy_busy_buffers_size 128k;

proxy_temp_file_write_size 128k;

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 /var/log/nginx/access.log main;

proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d;

proxy_temp_path /var/cache/nginx/proxy_cache/tmp;

upstream group1 {

server 192.168.127.135:80;

server 192.168.127.136:80;

}

server {

listen 80;

server_name www.test.com;

root /usr/share/nginx/html;

        index index.html index.htm;


location / {

try_files $uri $uri/ =404;


}

location /group1/M00 {

valid_referers none blocked server_names *.test.com;

if ($invalid_referer){

rewrite ^/ http://www.test.com/fangdao.html;

#return 403;

}

proxy_next_upstream http_502 http_504 error timeout invalid_header;

proxy_cache http-cache;

proxy_cache_valid 200 304 12h;

proxy_cache_key $uri$is_args$args;

proxy_pass http://group1;

expires 30d;

}

}

}

相關文章
相關標籤/搜索