nginx-常用配置

一、反向代理

 

    server {
        listen       15672;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {//被代理的路由
            root   html;
            proxy_pass http://172.18.0.2:15672;//实际服务器地址
            index  index.html index.htm;
        }

        #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   html;
        }

        # 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;
        #}
    }

 

二、负载均衡

   #轮询
   upstream server_list{ server
127.0.0.1:8080; server 127.0.0.1:8081; }
  #带权重轮询
  upstream server_list{
server 127.0.0.1:8080 weght=2;
    server 127.0.0.1:8081 weght=8;
}
  #iphash
  upstram server_list{
    ip_hash;
    server 127.0.0.1:8080;
    server 127.0.0.1:8081;
  }

  #最少连接

  upstream server_list{
    least_conn;
   server 127.0.0.1:8080;
    server 127.0.0.1:9090;
  } server { listen
8088; server_name localhost; location / { root html; proxy_pass http://server_list; index index.html index.htm; } }

 三、location匹配符(按优先级从高到低)

  •  = 全等匹配
  • ^~  普通字符前缀匹配
  • ~* 不区分大小写正则匹配
  • ~ 区分大小写正则匹配
  • /uri 通用前缀匹配
posted @ 2022-03-29 17:02  hugeQAQ  阅读(42)  评论(0编辑  收藏  举报