【发布时间】:2016-06-28 08:43:49
【问题描述】:
我正在尝试使用 nginx 做的是调用后端进行身份验证,如果响应成功,我将重定向到网站 1(例如 -google.com),如果身份验证失败,我将重定向到网站 2(facebook例如)。
下面是我的 nginx.conf-
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
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;
keepalive_timeout 65;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/default.conf;
}
default.conf 文件如下 -
server {
listen 80 default_server;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root /usr/share/nginx/html;
# index index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://backend_ip_Address;
set $my_var 0;
if ($status = "200"){
set $my_var 1;
}
#if($status = 4xx) {
# set $my_var 2;
#}
if ($my_var = 1){
proxy_pass http://www.google.com;
}
if ($my_var = 2) {
proxy_pass http://www.facebook.com;
}
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
我面临的问题是当我尝试使用此配置执行 sudo service nginx restart 时出现以下错误- 启动 nginx: nginx: [emerg] 未知“状态”变量
相同的 $status 也存在于 nginx.conf 日志配置中,它正确地记录响应代码,如 301、200 等。但相同的状态变量在 default.conf 文件中不起作用。对我做错了什么有帮助吗?
我尝试用 body_bytes_sent 标头替换状态,它的工作原理。
通过谷歌搜索https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=nginx++unknown+%22status%22+variable只有相关信息是https://www.drupal.org/node/2738983,但对解决这个问题没有多大帮助。
【问题讨论】:
标签: nginx