1、负载均衡,/usr/local/nginx/nginx.conf添加stream即可

http{
....
}
stream {
        server {
                listen          8080 reuseport;
                proxy_pass      netty;
        }
        upstream netty {
                server  192.168.180.68:8080;
                server  192.168.180.69:8080;
        }
}

2、添加文件服务器,在http中(如果性能不行,可参考http://blog.csdn.net/b_h_l/article/details/17508499)

server {
        listen       80;
        server_name  192.168.180.67;
        location / {
                root   /opt/test;
                index  index.php index.html index.htm;
                autoindex on;
                autoindex_exact_size off;
                autoindex_localtime on;
                }
 }

3、虚拟目录()

server {
        listen       80;
        server_name  localhost;
        location / {
                root /404.html;
                index  index.php index.html index.htm;
        }
        location /recfile {
                alias /home/netrec/;
                index  index.php index.html index.htm;
                autoindex on;
                autoindex_exact_size off;
                autoindex_localtime on;
        }
        location /test {
            proxy_pass http://ip:port;
        }
}

nginx的root和alias指令的区别

nginx配置下有两个指定目录的执行,root和alias

location /img//var/www/p_w_picpath/
location /img//var/www/p_w_picpath

alias是一个目录别名的定义,root则是最上层目录的定义。

还有一个重要的区别是alias后面必须要用“/”结束,否则会找不到文件的。。。而root则可有可无~~


4、refer防盗链

https://help.aliyun.com/knowledge_detail/6708458.html?pos=2


5、重定向到某个地址

server {
        listen 9000;
        server_name www.abc.com;
        rewrite ^/(.*)$ http://180.133.180.198:9002/$1
        permanent;
    }