前言
dnf是包管理器,起到很便捷的作用
配置安装
安装dnf包管理器
yum -y install epel-release
yum -y install dnf
yum -y update python*
yum -y install dnf-data dnf-plugins-core libdnf-devel libdnf python2-dnf-plugin-migrate dnf-automatic
dnf安装openresty
mkdir openresty && cd openresty
dnf -y install wget
wget 'https://openresty.org/package/centos/openresty.repo'
mv openresty.repo /etc/yum.repos.d/
dnf check-update
dnf -y install openresty
which openresty
file `which openresty`
openresty -V
systemctl start openresty
systemctl enable openresty
ps aux|grep nginx
curl 127.0.0.1
ln -snf /usr/local/openresty/nginx/sbin/nginx /usr/local/bin/nginx
dnf -y install openresty-resty
which resty
resty -e 'print("Hello Resty")'
dnf -y install openresty-doc
restydoc -s content_by_lua_file
dnf -y install openresty-opm
opm get pintsized/lua-resty-http
ls /usr/local/openresty/site/
resty -e 'require "resty.http"'
dnf -y install openresty-debug
which openresty-debug
file `which openresty-debug`
dnf list openresty-valgrind openresty-asan
dnf check-update
dnf upgrade 'openresty*'
dnf --disablerepo='*' --enablerepo="openresty" list available
streaming http
mkdir stream-resp && cd stream-resp
mkdir logs conf html
]# cat > conf/nginx.conf <<-EOF
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 8080 reuseport;
location = /test {
default_type application/octet-stream;
content_by_lua_block {
for i = 1, 4 do
ngx.say("hello", i)
ngx.flush(true)
ngx.sleep(1)
end
}
}
location / {
default_type text/html;
root html;
}
}
}
EOF
]# tree .
.
├── conf
│ └── nginx.conf
├── html
└── logs
3 directories, 1 file
]# openresty -p $PWD
curl 'http://127.0.0.1:8080/test'
hello1
hello2
hello3
hello4
]# cat > html/index.html <<-EOF
<!doctype html>
<html>
<body>
<script>
(function () {
let xhttp = new XMLHttpRequest();
xhttp.open("GET", "/test", true);
xhttp.send();
let div = document.getElementById("out")
let total_len = 0
let check_resp = function () {
let resp = xhttp.responseText
let len = resp.length
if (len > total_len) {
let new_data = resp.substring(total_len, len)
total_len = len;
div.innerHTML += new_data + "<br/>"
}
};
let timer = setInterval(check_resp, 1000);
check_resp();
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
check_resp();
clearInterval(timer);
div.innerHTML += "done<br/>";
}
};
})();
</script>
</body>
</html>
EOF
]# curl http://127.0.0.1:8080/index.html