nginx中配置简介

 一、location中的root和alias区别

  •  location中root含义
location /abc/ {
    root /data/www;
}

请求http://domain/abc/123.png 请求的在服务器上真正资源地址为 /data/www/abc/123.png
注意: root 真实路径是root指定值加上location指定的值。
  •  location中alias含义  alias指定的路径是location的别名,不管location的值怎么写,资源的真实路径都是 alias 指定的路径
location /abc/ {
    alias  /data/www/;
}

请求http://domain/abc/123.png 请求的在服务器上真正资源地址为  /data/www/123.png
注意:alias真实路径是alias指定的值,不包含location指定的值了

注意:

  1. 在一个location中,alias可以存在多个,但是root只能有一个
  2. alias只能存在与location中,但是root可以用在server、http和location中
  3. alias后面值必须要“/”结束,否则会找不到文件,而root的“/”可有可无

 

二、nginx中的全局变量

$args, 请求中的参数;
$content_length, HTTP请求信息里的"Content-Length";
$content_type, 请求信息里的"Content-Type";
$document_root, 针对当前请求的根路径设置值;
$document_uri, 与$uri相同;
$host, 请求信息中的"Host",如果请求中没有Host行,则等于设置的服务器名;
$limit_rate, 对连接速率的限制;
$request_method, 请求的方法,比如"GET""POST"等;
$remote_addr, 客户端地址;
$remote_port, 客户端端口号;
$remote_user, 客户端用户名,认证用;
$request_filename, 当前请求的文件路径名
$request_body_file
$request_uri, 请求的URI,带查询字符串;
$query_string, 与$args相同;
$scheme, 所用的协议,比如http或者是https,比如rewrite ^(.+)$ $scheme://example.com$1 redirect;
$server_protocol, 请求的协议版本,"HTTP/1.0""HTTP/1.1";
$server_addr, 服务器地址,如果没有用listen指明服务器地址,使用这个变量将发起一次系统调用以取得地址(造成资源浪费);
$server_name, 请求到达的服务器名;
$server_port, 请求到达的服务器端口号;
$uri, 请求的URI,可能和最初的值有不同,比如经过重定向之类的。
Ancient_browser:[$ancient_browser]

 Args:[$args]

 Binary_remote_addr:[$binary_remote_addr]

 Body_bytes_sent:[$body_bytes_sent]

 Bytes_received:[$bytes_received]

 Bytes_sent:[$bytes_sent]

 Connection:[$connection]

 Connection_requests:[$connection_requests]

 Connections_active:[$connections_active]

 Connections_reading:[$connections_reading]

 Connections_waiting:[$connections_waiting]

 Connections_writing:[$connections_writing]

 Connection_time:[$connection_time]

 Content_length:[$content_length]

 Content_type:[$content_type]

 Date_gmt:[$date_gmt]

 Date_local:[$date_local]

 Document_root:[$document_root]

 Document_uri:[$document_uri]

 Fastcgi_path_info:[$fastcgi_path_info]

 Fastcgi_script_name:[$fastcgi_script_name]


 Geoip_area_code:[$geoip_area_code]

 Geoip_city:[$geoip_city]

 Geoip_city_continent_code:[$geoip_city_continent_code]

 Geoip_city_country_code:[$geoip_city_country_code]

 Geoip_city_country_code3:[$geoip_city_country_code3]

 Geoip_city_country_name:[$geoip_city_country_name]

 Geoip_country_code:[$geoip_country_code]

 Geoip_country_code3:[$geoip_country_code3]

 Geoip_country_name:[$geoip_country_name]

 Geoip_dma_code:[$geoip_dma_code]

 Geoip_latitude:[$geoip_latitude]

 Geoip_longitude:[$geoip_longitude]

 Geoip_org:[$geoip_org]

 Geoip_postal_code:[$geoip_postal_code]

 Geoip_region:[$geoip_region]

 Geoip_region_name:[$geoip_region_name]


 Gzip_ratio:[$gzip_ratio]

 Host:[$host]

 Hostname:[$hostname]

 Http2:[$http2]

 Https:[$https]

 Invalid_referer:[$invalid_referer]

 Is_args:[$is_args]

 Jwt_claim_:[$jwt_claim_]

 Jwt_header_:[$jwt_header_]

 Limit_conn_status:[$limit_conn_status]

 Limit_rate:[$limit_rate]

 Limit_req_status:[$limit_req_status]

 Memcached_key:[$memcached_key]

 Modern_browser:[$modern_browser]

 Msec:[$msec]

 Msie:[$msie]

 Nginx_version:[$nginx_version]

 Pid:[$pid]

 Pipe:[$pipe]

 Protocol:[$protocol]


 Proxy_add_x_forwarded_for:[$proxy_add_x_forwarded_for]

 Proxy_host:[$proxy_host]

 Proxy_port:[$proxy_port]

 Proxy_protocol_addr:[$proxy_protocol_addr]

 Proxy_protocol_port:[$proxy_protocol_port]

 Proxy_protocol_server_addr:[$proxy_protocol_server_addr]

 Proxy_protocol_server_port:[$proxy_protocol_server_port]


 Query_string:[$query_string]

 Realip_remote_addr:[$realip_remote_addr]

 Realip_remote_port:[$realip_remote_port]

 Realpath_root:[$realpath_root]

 Remote_addr:[$remote_addr]

 Remote_port:[$remote_port]

 Remote_user:[$remote_user]


 Request:[$request]

 Request_body:[$request_body]

 Request_body_file:[$request_body_file]

 Request_completion:[$request_completion]

 Request_filename:[$request_filename]

 Request_id:[$request_id]

 Request_length:[$request_length]

 Request_method:[$request_method]

 Request_time:[$request_time]

 Request_uri:[$request_uri]


 Scheme:[$scheme]

 Secure_link:[$secure_link]

 Secure_link_expires:[$secure_link_expires]

 Sent_http_:[$sent_http_]

 Sent_trailer_:[$sent_trailer_]


 Server_addr:[$server_addr]

 Server_name:[$server_name]

 Server_port:[$server_port]

 Server_protocol:[$server_protocol]

 Session_log_binary_id:[$session_log_binary_id]

 Session_log_id:[$session_log_id]

 Session_time:[$session_time]

 Slice_range:[$slice_range]


 Spdy:[$spdy]

 Spdy_request_priority:[$spdy_request_priority]


 Ssl_cipher:[$ssl_cipher]

 Ssl_ciphers:[$ssl_ciphers]

 Ssl_client_cert:[$ssl_client_cert]

 Ssl_client_escaped_cert:[$ssl_client_escaped_cert]

 Ssl_client_fingerprint:[$ssl_client_fingerprint]

 Ssl_client_i_dn:[$ssl_client_i_dn]

 Ssl_client_i_dn_legacy:[$ssl_client_i_dn_legacy]

 Ssl_client_raw_cert:[$ssl_client_raw_cert]

 Ssl_client_s_dn:[$ssl_client_s_dn]

 Ssl_client_s_dn_legacy:[$ssl_client_s_dn_legacy]

 Ssl_client_serial:[$ssl_client_serial]

 Ssl_client_v_end:[$ssl_client_v_end]

 Ssl_client_verify:[$ssl_client_verify]

 Ssl_client_v_remain:[$ssl_client_v_remain]

 Ssl_client_v_start:[$ssl_client_v_start]

 Ssl_curves:[$ssl_curves]

 Ssl_early_data:[$ssl_early_data]

 Ssl_preread_alpn_protocols:[$ssl_preread_alpn_protocols]

 Ssl_preread_protocol:[$ssl_preread_protocol]

 Ssl_preread_server_name:[$ssl_preread_server_name]

 Ssl_protocol:[$ssl_protocol]

 Ssl_server_name:[$ssl_server_name]

 Ssl_session_id:[$ssl_session_id]

 Ssl_session_reused:[$ssl_session_reused]


 Status:[$status]

 Tcpinfo_rcv_space:[$tcpinfo_rcv_space]

 Tcpinfo_rtt:[$tcpinfo_rtt]

 Tcpinfo_rttvar:[$tcpinfo_rttvar]

 Tcpinfo_snd_cwnd:[$tcpinfo_snd_cwnd]

 Time_iso8601:[$time_iso8601]

 Time_local:[$time_local]

 Uid_got:[$uid_got]

 Uid_reset:[$uid_reset]

 Uid_set:[$uid_set]


 Upstream_addr:[$upstream_addr]

 Upstream_bytes_received:[$upstream_bytes_received]

 Upstream_bytes_sent:[$upstream_bytes_sent]

 Upstream_cache_status:[$upstream_cache_status]

 Upstream_connect_time:[$upstream_connect_time]

 Upstream_cookie_:[$upstream_cookie_]

 Upstream_first_byte_time:[$upstream_first_byte_time]

 Upstream_header_time:[$upstream_header_time]

 Upstream_http_:[$upstream_http_]

 Upstream_queue_time:[$upstream_queue_time]

 Upstream_response_length:[$upstream_response_length]

 Upstream_response_time:[$upstream_response_time]

 Upstream_session_time:[$upstream_session_time]

 Upstream_status:[$upstream_status]

 
 Uri:[$uri]

参考文献:http://nginx.org/en/docs/varindex.html

原文地址:https://www.cnblogs.com/gavin11/p/14845271.html