Nginx fastcgi param没有得到CodeIgniter

时间:2017-03-16 20:33:54

标签: codeigniter nginx codeigniter-2 fastcgi

我在nginx虚拟主机文件中设置了fastcgi_param ENVIRONMENT,但我无法在CodeIgniter中访问该值:

var_dump(defined('ENVIRONMENT')); //outputs false

完整的nginx虚拟主机文件:

server {
    listen      80;

    # Hostnames alias
    server_name webapp1;

    root /home/edson/repositorios/webapp1;

    index       index.php index.html;

    location /bec/admin {
        try_files $uri $uri/ /bec/admin/index.php$is_args$args;
    }
    location /bec {
        try_files $uri $uri/ /bec/index.php$is_args$args;
    }

    #
    # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include /etc/nginx/php.conf;
        fastcgi_param ENVIRONMENT development;
    }

    # Nginx Cache Control for Static Files (Browser Cache Control Directives)
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|xls|xlsx|doc|docx|csv|txt)$ {
        access_log        off;
        log_not_found     off;
        expires           max;
    }

    #
    # deny access to .htaccess files, and hidden files, which starts with dot (.), if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }
}

我做错了吗?

1 个答案:

答案 0 :(得分:0)

这是一个环境变量,因此可以通过getenv访问:

  

获取环境变量的值

实施例

getenv('ENVIRONMENT');