企業級應用服務動靜分離
阿新 • • 發佈:2018-05-02
負載均衡 動靜分離 linux
此處只貼出實現代碼
背景:通過Nginx實現7層動靜分離,即通過Nginx反向代理配置規則實現讓動態資源和靜態資源及其他業務分別由不同的服務器解析。
測試機器準備工作
7層動靜分離案例
負載均衡lb01
[root@lb01 ~]# cat /application/nginx/conf/proxy.conf 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;
[root@lb01 ~]# cat /application/nginx/conf/nginx.conf error_log logs/error.log error; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream static_pools { server 10.0.0.7:80 weight=1; #apache } upstream upload_pools { server 10.0.0.7:8080 weight=1; #apache } upstream default_pools { server 10.0.0.8:80 weight=1; #nginx } server { listen 80; server_name blog.51cto.com; location / { proxy_pass http://default_pools; include proxy.conf; } location /static/ { proxy_pass http://static_pools; include proxy.conf; } location /upload/ { proxy_pass http://upload_pools; include proxy.conf; } } }
Web02節點配置
[root@web02 ~]# cat /application/apache/htdocs/blog/static/index.html Static [root@web02 ~]# cat /application/apache/htdocs/blog8080/upload/index.html Upload [root@web02 extra]# pwd /application/apache/conf/extra [root@web02 extra]# awk ‘NR>16 && NR<24‘ httpd-vhosts.conf <VirtualHost *:8080> ServerAdmin [email protected] DocumentRoot "/application/apache2.2.31/htdocs/blog8080" ServerName blog.51cto.com ErrorLog "logs/blog8080-error_log" CustomLog "logs/blog8080-access_log" common </VirtualHost>
開啟端口監聽vim /application/apache/conf/httpd.conf
瀏覽器中測試:
http://blog.51cto.com/static/
http://blog.51cto.com/upload/
http://blog.51cto.com
負載均衡01-日誌
企業級應用服務動靜分離