Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've woken up this morning to find that a new Nginx server I've been teaching myself with is no longer serving websites. It looks like this is because Nginx is no longer running. When I try to start it though, I get this error:

Starting nginx: nginx: [emerg] unknown "https" variable
                                                           [FAILED]

Now as far as I'm aware, nothing has been changed and it was running fine yesterday, but nothing I've looked up so far has helped me find a solution to this.

If I run service nginx restart, I get the below:

nginx: [emerg] unknown "https" variable
nginx: configuration file /etc/nginx/nginx.conf test failed

So far I've everything I've been able to find about this, such as here and a few other places: http://www.howtoforge.com/forums/showthread.php?t=60733 says to comment out lines in fastcgi_params, however, I don't have those lines in the first place.

I've also tried commenting out references to https just to see what happens, but it doesn't seem to make any difference.

My Nginx.conf file is:

user              nginx;
worker_processes  1;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    autoindex off;

    map $scheme $fastcgi_https { ## Detect when HTTPS is used
        default off;
        https on;
    }

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;
    gzip_comp_level 2;
    gzip_proxied any;
    #gzip_types      text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;


    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;

}

It is presently running a test Magento site, the .conf file for it looks like:

    server {
    listen 80;
    server_name freshtrifle.com;
    rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
    listen 80;
## SSL directives might go here
    server_name www.freshtrifle.com *.freshtrifle.com; ## Domain is here twice so server_name_in_redirect will favour the www
    root /var/www/freshtrifle.com;

    location / {
        index index.html index.php; ## Allow a static html file to be shown first
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        expires 30d; ## Assume all files are cachable
    }

    ## These locations would be hidden by .htaccess normally
    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }

    location /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
        autoindex            on;
    }

    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }

    location ~ .php$ { ## Execute PHP scripts
        if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

        expires        off; ## Do not cache dynamic content
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
        fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }
}

My fastcgi_params file looks like:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

Does anyone see anything I'm missing? Is there another file I need to look at?

Any advice would be greatly appreciated, thanks.

share|improve this question
    
What nginx version do you use? –  VBart Mar 4 '13 at 11:39
    
1.0.15 at the moment. –  Matt Mar 4 '13 at 13:21
add comment

3 Answers

up vote 2 down vote accepted

Update Nginx to version 1.2.7 and so far this does seem to have fixed it. None of the .conf files have changed so I'm assuming there is something in there that was incompatible. I don't know what exactly or why it didn't stop working sooner, but at this stage all seems to be running as it should after updating it.

share|improve this answer
3  
Changes with nginx 1.1.11 (12 Dec 2011) Feature: the $https variable. @ nginx.org/en/CHANGES –  VBart Mar 4 '13 at 15:08
add comment

Add this to your Nginx config within http {}. The problem with older Nginx versions is that the variable is not defined. This defines the variable.

map $scheme $fastcgi_https {
    default off;
    https on;
}

Not having $_SERVER['HTTPS'] set will not keep SSL from working in general but will send Magento into an infinite redirect loop on secure pages. Magento does a check to see if the current page should be secure, then checks if it is actually secure. If not, it redirects to the secure URL. The problem is that this check checks for the presence of $_SERVER['HTTPS'].

share|improve this answer
add comment

in the event Google brings someone in my situation here, like it did me:

I am running Nginx 1.2.7 on our ubuntu dev server and just went through exactly this. I got the conf file from the Magento wiki and made a couple changes:

» Removed top server section to get rid of the www. rewrites
» changed magento.com to just magento
» near line 51 (as shown on that link above), I commented out the line with the offending variable.
# fastcgi_param HTTPS $fastcgi_https;
» executed sudo service nginx restart

And now my Magento 1.7.0.2 install could march forward. If you're here and you're getting a 404 error on Magento install, you need the above config file.

Tick the box for skipping base URL validation when the time comes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.