几个常用的openresty配置文件
location /testz {
default_type text/plain;
echo request_uri "$request_uri";
echo Server addr "$server_addr";
echo remote_addr "$remote_addr";
echo http_x_http_forwarded_for "$http_x_http_forwarded_for";
echo proxy_add_x_forwarded_for "$proxy_add_x_forwarded_for";
echo http_x_forwarded_for "$http_x_forwarded_for";
echo http_accept_language "$http_accept_language";
echo http_user_agent "$http_user_agent";
echo content_length "$content_length";
echo content_type "$content_type";
echo document_root "$document_root";
echo document_uri "$document_uri";
echo limit_rate "$limit_rate";
echo request_method "$request_method";
echo remote_port "$remote_port";
echo remote_user "$remote_user";
echo request_filename "$request_filename";
echo request_uri "$request_uri";
echo query_string "$query_string";
echo args "$args";
echo scheme "$scheme";
echo server_protocol "$server_protocol";
#echo server_addr "$server_addr";
echo server_name "$server_name";
echo server_port "$server_port";
echo URI "$uri";
echo http_referer $http_referer;
echo request $request;
echo connection $connection;
echo remote_user $remote_user;
echo request_time $request_time;
echo hostname $hostname;
echo realpath_root $realpath_root;
echo proxy_protocol_addr $proxy_protocol_addr;
echo http_via $http_via;
echo http_host $http_host;
echo time_local $time_local;
#echo SESSION $session;
echo http_cookie $http_cookie;
echo "man man lai 2";
#echo $http_cookie ;
#echo $user_cookie;
#echo $cookie_PHPSESSID;
#echo $http_host;
set_sha1 $hash_ip $remote_addr;
echo hash_ip $hash_ip;
echo connection $connection;
echo connection_requests $connection_requests;
echo connections_active $connections_active;
echo connections_reading $connections_reading;
echo connections_waiting $connections_waiting;
echo connections_writing $connections_writing;
if ( $http_cookie = '') {echo "You cookie is null";}
#if {$connection_requests >= '100') {echo yes;}
set $testvar 233;
rewrite_by_lua 'ngx.var.testvar = 123';
echo $testvar;
}
cat googleapis.conf
sub_filter_once off;
sub_filter_types text/css text/xml text/javascript;
sub_filter "https://fonts.googleapis.com" "/assets/vendor/googleapis";
sub_filter "//fonts.googleapis.com" "/assets/vendor/googleapis";
sub_filter "https://ajax.googleapis.com" "/assets/vendor/ajax";
sub_filter "https://fonts.gstatic.com" "/assets/vendor/fonts_gstatic";
#sub_filter "https://www.google.com/jsapi" "/assets/vendor/gstatic/charts/loader.js";
proxy_hide_header Link;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
location ~ /assets/vendor/googleapis/ {
proxy_set_header Accept-Encoding "";
rewrite ^/assets/vendor/googleapis/(.+)$ /$1 break;
proxy_pass https://fonts.googleapis.com;
proxy_set_header Host "fonts.googleapis.com";
proxy_set_header User-Agent $http_user_agent;
expires 1d;
sub_filter "https://fonts.gstatic.com" "/assets/vendor/fonts_gstatic";
}
location ~ /assets/vendor/fonts_gstatic/ {
rewrite ^/assets/vendor/fonts_gstatic/(.+)$ /$1 break;
proxy_pass https://fonts.gstatic.com;
proxy_set_header Host "fonts.gstatic.com";
proxy_set_header User-Agent $http_user_agent;
expires 1y;
}
location ~ /assets/vendor/gstatic/ {
rewrite ^/assets/vendor/gstatic/(.+)$ /$1 break;
proxy_pass https://www.gstatic.com;
proxy_set_header Host "www.gstatic.com";
expires 1y;
}
location ~ /assets/vendor/ajax/ {
rewrite ^/assets/vendor/ajax/(.+)$ /$1 break;
proxy_pass https://gajax.googleapis.com;
proxy_set_header Host ajax.googleapis.com;
expires 1y;
}
cat gstatic.conf
sub_filter_once off;
sub_filter_types text/css;
sub_filter https://fonts.gstatic.com/ /gstatic/;
sub_filter https://fonts.googleapis.com/ /googleapis/;
sub_filter http://fonts.gstatic.com/ /gstatic/;
sub_filter http://fonts.googleapis.com/ /googleapis/;
sub_filter //fonts.gstatic.com/ /gstatic/;
sub_filter //fonts.googleapis.com/ /googleapis/;
#proxy_bind $remote_addr transparent;
proxy_hide_header Link;
location /gstatic/ {
resolver 8.8.8.8;
proxy_set_header Host fonts.gstatic.com;
proxy_pass http://fonts.gstatic.com/;
}
location /googleapis/ {
resolver 8.8.8.8;
proxy_set_header Host fonts.googleapis.com;
proxy_pass http://fonts.googleapis.com/;
}
cat error.conf
error_page 404 @404page;
error_page 502 503 504 @502page;
location @502page {
default_type text/plain;
echo "Backend server time out";
}
location @404page {
default_type text/plain;
echo "Not Found";
}
cat cc.conf
set $hash_ip HASHKEY2015$remote_addr;
set_sha1 $hash_var $hash_ip;
if ($cookie_cfcuid != "$hash_var"){
add_header Set-Cookie "cfcuid=$hash_var";
rewrite .* "https://$http_host$uri" redirect;
}
none



