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

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

user  www www;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

	    gzip  on;
	    gzip_min_length 1k;
	    gzip_buffers 16 64k;
	    gzip_http_version 1.1;
	    gzip_comp_level 9;
    	gzip_types text/plain application/x-javascript text/css application/xml;
	    gzip_vary on;
	upstream webservers{
		server 192.168.1.82;
		server 192.168.1.88;
	}
	proxy_cache_path /data/nginx/cache/webserver levels=1:2 keys_zone=webserver:20m max_size=1g;
	server{
        	listen       80;
        	server_name  song.com;
		index index.html idnex.htm;
		root /data0/htdocs/www;

#....................................................防盗链...............	

	 #location ~ .*\.(|jpg|gif|png)$ {
			#root /data0/htdocs/www/;
	 		#valid_referers none  blocked *.demo.com demo.com 192.168.1.75;
        	        #if ($invalid_referer){
                        #rewrite ^/ http://www.765h.com/error.html;
                        # return 403;
                #}
	#}
#...................................................防盗链end....................
#......................................................模块缓存
	# location /download {
	#	root /data0/htdocs/www/;
  	#	accesskey             on;
 	 #       accesskey_hashmethod  md5;
  	#	accesskey_arg         "key";
  	#	accesskey_signature   "mypass$remote_addr";
	#}
#................................................................................
             #add_header X-Via $server_addr;
             #add_header X-Cache $upstream_cache_status;
#........................................................动静分离..................
        location ~ (\.php)$ {
                   proxy_pass http://webservers;

        }
#......................................................end 动静分离................
 #...................................................页面缓存
        #location / {
         #  root   /data0/htdocs/www;
          # index  index.html index.php  index.htm;
	   #proxy_pass      http://webservers;
         # proxy_set_header  X-Real-IP  $remote_addr;
          # proxy_cache webserver;
          #proxy_cache_valid 200 10m;
#.........................................................end 页面缓存
	#location /img/ {
 	   #root /data/img/;
   	   #valid_referers none blocked *.demo.com demo.com;
           #if ($invalid_referer) {
          #         rewrite  ^/  http://www.demo.com/images/error.gif;
         #          #return   403;
   	#	 }
	#}
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /data0/htdocs/www;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }

}
时间: 2024-08-28 23:12:24

nginx 防盗链+动静分离+反向代理+缓存+负载均衡的相关文章

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

修改nginx/conf/nginx.conf,修改完后如下: [php] view plaincopyprint? user  www www; worker_processes  1; #error_log  logs/error.log; #error_log  logs/error.log  notice; #error_log  logs/error.log  info; #pid        logs/nginx.pid; events { worker_connections 

Nginx安装、性能测试、反向代理、负载均衡实例

一.nginx安装 我使用的环境是64位 Ubuntu 14.04.nginx依赖以下模块: l gzip模块需要 zlib 库 l rewrite模块需要 pcre 库 l ssl 功能需要openssl库 1.1.安装pcre l 获取pcre编译安装包,在http://www.pcre.org/上可以获取当前最新的版本 l 解压缩pcre-xx.tar.gz包. l 进入解压缩目录,执行./configure. l make & make install 1.2.安装openssl l 获

基于nginx和tengine的tcp反向代理,负载均衡 安装和配置

先下载nginx_tcp_proxy_module模块. wget https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip 先看看自己原来nginx安装有哪些模块(编译参数): [[email protected]]# /tengine/sbin/nginx -VTengine version: Tengine/2.1.1 (nginx/1.6.2)built by gcc 4.4.7 20120313 (Re

Nginx反向代理,负载均衡,redis session共享,keepalived高可用

相关知识自行搜索,直接上干货... 使用的资源: nginx主服务器一台,nginx备服务器一台,使用keepalived进行宕机切换. tomcat服务器两台,由nginx进行反向代理和负载均衡,此处可搭建服务器集群. redis服务器一台,用于session的分离共享. nginx主服务器:192.168.50.133 nginx备服务器:192.168.50.135 tomcat项目服务器1:192.168.50.137 tomcat项目服务器2:192.168.50.139 redis服

nginx反向代理相关 负载均衡

一.反向代理 1.1.upstream简介 nginx的upstream可以同时实现反向代理和负载均衡,目前upstream支持4种方式的分配 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况. 2.ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题. 3.fair(第三方) 按后端服

Nginx反向代理、负载均衡、页面缓存、URL重写及读写分离详解

大纲 一.前言 二.环境准备 三.安装与配置Nginx 四.Nginx之反向代理 五.Nginx之负载均衡 六.Nginx之页面缓存 七.Nginx之URL重写 八.Nginx之读写分离 注,操作系统为 CentOS 6.4 x86_64 , Nginx 是版本是最新版的1.4.2,所以实验用到的软件请点击这里下载:http://yunpan.cn/QXIgqMmVmuZrm 一.前言 在前面的几篇博文中我们主要讲解了Nginx作为Web服务器知识点,主要的知识点有nginx的理论详解.ngin

Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解

大纲 一.前言 二.环境准备 三.安装与配置Nginx 四.Nginx之反向代理 五.Nginx之负载均衡 六.Nginx之页面缓存 七.Nginx之URL重写 八.Nginx之读写分离 注,操作系统为 CentOS 6.4 x86_64 , Nginx 是版本是最新版的1.4.2,所以实验用到的软件请点击这里下载:http://yunpan.cn/QXIgqMmVmuZrm 一.前言 在前面的几篇博文中我们主要讲解了Nginx作为Web服务器知识点,主要的知识点有nginx的理论详解.ngin

马哥学习笔记二十八——nginx反向代理,负载均衡,缓存,URL重写及读写分离

Nginx反向代理 Nginx通过proxy模块实现反向代理功能.在作为web反向代理服务器时,nginx负责接收客户请求,并能够根据URI.客户端参数或其它的处理逻辑将用户请求调度至上游服务器上(upstream server).nginx在实现反向代理功能时的最重要指令为proxy_pass,它能够将location定义的某URI代理至指定的上游服务器(组)上.如下面的示例中,location的/uri将被替换为上游服务器上的/newuri. location /uri { proxy_pa

[转载]Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解

大纲 一.前言 二.环境准备 三.安装与配置Nginx 四.Nginx之反向代理 五.Nginx之负载均衡 六.Nginx之页面缓存 七.Nginx之URL重写 八.Nginx之读写分离 注,操作系统为 CentOS 6.4 x86_64 , Nginx 是版本是最新版的1.4.2,所以实验用到的软件请点击这里下载:http://yunpan.cn/QXIgqMmVmuZrm 一.前言 在前面的几篇博文中我们主要讲解了Nginx作为Web服务器知识点,主要的知识点有nginx的理论详解.ngin