今天早上醒来,我发现我一直在自学的一个新的 Nginx 服务器不再为网站提供服务。这似乎是因为 Nginx 不再运行。但是当我尝试启动它时,我收到此错误:
Starting nginx: nginx: [emerg] unknown "https" variable
[FAILED]
据我所知,现在什么都没有改变,昨天运行良好,但到目前为止我查找的任何东西都没有帮助我找到解决方案。
如果我运行 service nginx restart,我会得到以下结果:
nginx: [emerg] unknown "https" variable
nginx: configuration file /etc/nginx/nginx.conf test failed
到目前为止,我已经找到有关此问题的所有信息,例如这里和其他一些地方:http://www.howtoforge.com/forums/showthread.php?t=60733说要注释掉 fastcgi_params 中的行,但是,我首先没有这些行。
我也尝试注释掉对 https 的引用只是为了看看会发生什么,但似乎没有任何区别。
我的 Nginx.conf 文件是:
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;
}
它目前正在运行测试 Magento 站点,它的 .conf 文件如下所示:
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
}
}
我的 fastcgi_params 文件如下所示:
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;
有人发现我遗漏了什么吗?我还需要查看其他文件吗?
非常感谢您的任何建议,谢谢。
答案1
将其添加到您的 Nginx 配置中的 http {} 中。旧版 Nginx 的问题是未定义该变量。这定义了变量。
map $scheme $fastcgi_https {
default off;
https on;
}
不设置 $_SERVER['HTTPS'] 不会阻止 SSL 正常工作,但会使 Magento 在安全页面上陷入无限重定向循环。Magento 会检查当前页面是否应该是安全的,然后检查它是否真的安全。如果不是,它会重定向到安全 URL。问题是此检查检查了 $_SERVER['HTTPS'] 是否存在。
答案2
将 Nginx 更新至版本 1.2.7,到目前为止,这似乎已经解决了问题。所有 .conf 文件均未发生更改,因此我假设其中存在不兼容的内容。我不知道具体是什么问题,也不知道为什么它没有更早停止工作,但目前看来,更新后一切似乎都正常运行。
答案3
如果谷歌把与我处境相同的人带到这里,就像我一样:
我在我们的 ubuntu 开发服务器上运行 Nginx 1.2.7,刚刚经历了这一切。我得到了 conf 文件来自 Magento 维基并做了一些修改:
» 删除了顶部server
部分以摆脱 www。重写
» 将 magento.com 更改为 magento
» 在第 51 行附近(如上面的链接所示),我注释掉了有问题的变量的行。
# fastcgi_param HTTPS $fastcgi_https;
» 执行sudo service nginx restart
现在我的 Magento 1.7.0.2 安装可以继续了。如果您在这里,并且在安装 Magento 时收到 404 错误,则需要上述配置文件。
勾选该框可在时间到时跳过基本 URL 验证。