码迷,mamicode.com
首页 > 其他好文 > 详细

nginx 防盗链+动静分离+反向代理+缓存+负载均衡 (转发)

时间:2015-05-13 12:45:05      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

修改nginx/conf/nginx.conf,修改完后如下:

 

  1. user  www www; 
  2. worker_processes  1; 
  3.  
  4. #error_log  logs/error.log; 
  5. #error_log  logs/error.log  notice; 
  6. #error_log  logs/error.log  info; 
  7.  
  8. #pid        logs/nginx.pid; 
  9.  
  10. events { 
  11.     worker_connections  1024; 
  12.  
  13. http { 
  14.     include       mime.types; 
  15.     default_type  application/octet-stream; 
  16.  
  17.     #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘ 
  18.     #                  ‘$status $body_bytes_sent "$http_referer" ‘ 
  19.     #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘; 
  20.  
  21.     #access_log  logs/access.log  main; 
  22.  
  23.     sendfile        on; 
  24.     #tcp_nopush     on; 
  25.  
  26.     #keepalive_timeout  0; 
  27.     keepalive_timeout  65; 
  28.  
  29.         gzip  on; 
  30.         gzip_min_length 1k; 
  31.         gzip_buffers 16 64k; 
  32.         gzip_http_version 1.1; 
  33.         gzip_comp_level 9; 
  34.         gzip_types text/plain application/x-javascript text/css application/xml; 
  35.         gzip_vary on; 
  36.     upstream webservers{ 
  37.         server 192.168.1.82; 
  38.         server 192.168.1.88; 
  39.     } 
  40.     proxy_cache_path /data/nginx/cache/webserver levels=1:2 keys_zone=webserver:20m max_size=1g; 
  41.     server{ 
  42.             listen       80; 
  43.             server_name  song.com; 
  44.         index index.html idnex.htm; 
  45.         root /data0/htdocs/www; 
  46.  
  47. #....................................................防盗链...............  
  48.  
  49.      #location ~ .*\.(|jpg|gif|png)$ { 
  50.             #root /data0/htdocs/www/;                
  51.             #valid_referers none  blocked *.demo.com demo.com 192.168.1.75; 
  52.                     #if ($invalid_referer){ 
  53.                         #rewrite ^/ http://www.765h.com/error.html; 
  54.                         # return 403; 
  55.                 #} 
  56.     #} 
  57. #...................................................防盗链end.................... 
  58. #......................................................模块缓存 
  59.     # location /download { 
  60.     #   root /data0/htdocs/www/; 
  61.     #   accesskey             on; 
  62.      #       accesskey_hashmethod  md5; 
  63.     #   accesskey_arg         "key"; 
  64.     #   accesskey_signature   "mypass$remote_addr"; 
  65.     #} 
  66. #................................................................................ 
  67.              #add_header X-Via $server_addr; 
  68.              #add_header X-Cache $upstream_cache_status; 
  69. #........................................................动静分离.................. 
  70.         location ~ (\.php)$ { 
  71.                    proxy_pass http://webservers; 
  72.  
  73.         } 
  74. #......................................................end 动静分离................ 
  75. #...................................................页面缓存 
  76.         #location / { 
  77.          #  root   /data0/htdocs/www; 
  78.           # index  index.html index.php  index.htm; 
  79.        #proxy_pass      http://webservers; 
  80.          # proxy_set_header  X-Real-IP  $remote_addr; 
  81.           # proxy_cache webserver; 
  82.           #proxy_cache_valid 200 10m; 
  83. #.........................................................end 页面缓存 
  84.     #location /img/ { 
  85.        #root /data/img/; 
  86.        #valid_referers none blocked *.demo.com demo.com; 
  87.            #if ($invalid_referer) { 
  88.           #         rewrite  ^/  http://www.demo.com/images/error.gif; 
  89.          #          #return   403; 
  90.     #    } 
  91.     #} 
  92.         #error_page  404              /404.html; 
  93.  
  94.         # redirect server error pages to the static page /50x.html 
  95.         # 
  96.         error_page   500 502 503 504  /50x.html; 
  97.         location = /50x.html { 
  98.             root   /data0/htdocs/www; 
  99.         } 
  100.  
  101.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  102.         # 
  103.         #location ~ \.php$ { 
  104.         #    proxy_pass   http://127.0.0.1; 
  105.         #} 
  106.  
  107.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  108.         # 
  109.         #location ~ \.php$ { 
  110.         #    root           html; 
  111.         #    fastcgi_pass   127.0.0.1:9000; 
  112.         #    fastcgi_index  index.php; 
  113.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 
  114.         #    include        fastcgi_params; 
  115.         #} 
  116.  
  117.         # deny access to .htaccess files, if Apache‘s document root 
  118.         # concurs with nginx‘s one 
  119.         # 
  120.         #location ~ /\.ht { 
  121.         #    deny  all; 
  122.         #} 
  123.     } 
  124.  
  125.  
  126.     # another virtual host using mix of IP-, name-, and port-based configuration 
  127.     # 
  128.     #server { 
  129.     #    listen       8000; 
  130.     #    listen       somename:8080; 
  131.     #    server_name  somename  alias  another.alias; 
  132.  
  133.     #    location / { 
  134.     #        root   html; 
  135.     #        index  index.html index.htm; 
  136.     #    } 
  137.     #} 
  138.  
  139.  
  140.     # HTTPS server 
  141.     # 
  142.     #server { 
  143.     #    listen       443; 
  144.     #    server_name  localhost; 
  145.  
  146.     #    ssl                  on; 
  147.     #    ssl_certificate      cert.pem; 
  148.     #    ssl_certificate_key  cert.key; 
  149.  
  150.     #    ssl_session_timeout  5m; 
  151.  
  152.     #    ssl_protocols  SSLv2 SSLv3 TLSv1; 
  153.     #    ssl_ciphers  HIGH:!aNULL:!MD5; 
  154.     #    ssl_prefer_server_ciphers   on; 
  155.  
  156.     #    location / { 
  157.     #        root   html; 
  158.     #        index  index.html index.htm; 
  159.     #    } 
  160.      
  161.  

原文地址:http://blog.csdn.net/php_1314/article/details/45645773

nginx 防盗链+动静分离+反向代理+缓存+负载均衡 (转发)

标签:

原文地址:http://www.cnblogs.com/xwj517537691/p/4499838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!