nginx配置

通过header调度

有时候会遇到一些流量调度的问题,可以采用在header中添加标识信息,去做到流量的调度

  • 请求中如果携带 trace: gray 的头信息,会将请求转发到百度上
  • curl -H 'trace: gray' http://127.0.0.1 请求转发到百度
  • curl http://127.0.0.1 请求转发到本地服务
  • nginx的header头信息中,键不区分大小写,- 会被替换成 _
server {
    listen          80;
    server_name     localhost;

    location / {
        if ($http_trace = 'gray'){
            proxy_pass http://www.baidu.com;
        }
    }
}

目录浏览

Nginx打开目录浏览功能

  • /usr/share/nginx/conf/conf.d/ht 文件为apache支持的账号密码对,加密方式可以为 htpasswd、md5
  • 访问 http://127.0.0.1/list
server {
    listen          80;
    server_name     localhost;

    # 如果有中文,请求配置该项
    charset utf-8;

    # 文件列表
    location /list {
        autoindex                   on;
        autoindex_exact_size        off;
        autoindex_localtime         on;

		# 登录权限认证,可选
        auth_basic                  "Server Auth";
        auth_basic_user_file        /usr/share/nginx/conf/conf.d/ht;
    }
}

Nginx支持pathinfo模式

# nginx
location ~ \.php$ {
    root            html;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    include         fastcgi_params;
}

配置成

# nginx
location ~ \.php(.*)$ { # 正则匹配.php后的pathinfo部分
    root            html;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   PATH_INFO $1; # 把pathinfo部分赋给PATH_INFO变量
    include         fastcgi_params;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值