nginx http配置说明,逐渐完善。

http {
    # .........省略部分默认配置

    # 字符集配置
    charset utf-8;

    # 包压缩配置
    # 开启gzip
    gzip on;

    # 启用gzip压缩的最小文件,小于设置值的文件将不会压缩
    gzip_min_length 1k;

    # gzip 压缩级别,1-9,数字越大压缩的越好,也越占用CPU时间,后面会有详细说明
    gzip_comp_level 5;

    # 进行压缩的文件类型。javascript有多种形式。其中的值可以在 mime.types 文件中找到。
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

    # 是否在http header中添加Vary: Accept-Encoding,建议开启
    gzip_vary on;

    # 禁用IE 6 gzip
    gzip_disable "MSIE [1-6]\.";

    # 重定向配置(例子)
    server {
        listen 80;
        server_name  abc.com;
        rewrite ^/(.*) http://www.abc.com/$1 permanent;
    }

    # 站点配置(例子)
    server {
        listen       80;
        server_name  www.abc.com; # 主机名
        root   /data/cbg.com/public; # 项目index.php所在目录
        index  index.php index.html index.htm;

        # 接口转发(例子)
        location /api { # 我测试是,location最后结尾带'/'就是301,不带'/'就是直接转发包。
            # 例:abc.com/api/user/info 会转发到 http://api.com/admin/user/info
            # 当proxy_pass的地址带path时,就是把匹配出来的path截取掉(/api),把后面的path(/user/info)附加到proxy_pass的地址最后。
            # 当proxy_pass不带path也不带'/',就会把所有path加到域名后面。
            proxy_pass       http://api.com/admin; 
            # 请求头,配置格式为 proxy_set_header 键 值
            proxy_set_header Host            $proxy_host; # 跳转的主机名,默认是域名。可自定义:例如这里定义值为abc,相应的添加abc到http://api.com/admin站点的server_name中,即可识别。
            proxy_set_header X-Real-IP       $remote_addr; # 远程IP地址。为了主机可获取到客户端的IP地址
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location / {
            # 本例使用laravel的rewrite,如果是其他框架,请使用相应配置。
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_pass 172.18.1.11:9000; # php容器的IP
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
            expires 30d;
            access_log off;
        }

        location ~ .*\.(js|css)?$ {
            expires 7d;
            access_log off;
        }

        location ~ /\.ht {
            deny all;
        }

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值