nginx笔记
1、直接返回来访IP
location /ip {
default_type text/plain;
return 200 $remote_addr;
}
2、流转发及写日志、开启websocket:
log_format stream '$remote_addr ($remote_user) $time_local' ;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
map $uri $log_stream_user {
default 0;
"~SND" 1;
}
stream {
server {
listen 15678;
proxy_pass 192.168.1.99:1234;
}
server {
listen 8073;
access_log /var/log/nginx/access_8073.log stream buffer=1k flush=5s if=$log_stream_user;
location / {
proxy_pass http://192.168.1.1:8073;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
auth_basic "Wellcome to visit ......";
auth_basic_user_file htpasswd;
}
location ^~ /admin {
deny all;
}
}
}