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.

When nginx server is configured this way:

server {
  listen 80;
  listen 443 ssl;
  server_name www.example.org;
  ...
}

how can be detected that the request came via HTTP or HTTPS?

(E.g. $http_port is unusable, because the port is not specified explicitly, therefore it's empty)

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

http://nginx.org/en/docs/http/ngx_http_core_module.html#variables

  • $https — “on” if connection operates in SSL mode, or an empty string otherwise
  • $scheme — request scheme, “http” or “https”
share|improve this answer
add comment

Why not separate each into their own server directive and specify a log per server context:

server {
  listen           80;
  server_name      www.nginx.org;
  log_format gzip '$remote_addr - $remote_user [$time_local]  '
                  '"$request" $status $bytes_sent '
                  '"$http_referer" "$http_user_agent" "$gzip_ratio"';

  access_log  /spool/logs/nginx-access.log  gzip  buffer=32k;
  error_log /var/log/nginx/nginx-error.log error;
}

server {
  listen           443 default_server ssl;
  server_name      secure.nginx.org;
  log_format gzip '$remote_addr - $remote_user [$time_local]  '
                  '"$request" $status $bytes_sent '
                  '"$http_referer" "$http_user_agent" "$gzip_ratio"';

  access_log  /var/log/nginx/nginx_ssl-access.log  gzip  buffer=32k;
  error_log /var/log/nginx/nginx_ssl-error.log error;
}

You could then view each log separately to see where the access or error came from.

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.