前言:
而今大家对“mercurialnginx”大约比较关注,看官们都想要分析一些“mercurialnginx”的相关知识。那么小编同时在网络上网罗了一些对于“mercurialnginx””的相关内容,希望看官们能喜欢,朋友们快快来学习一下吧!reference:
nginx.org/en/docs/njs/ An official nginx docs for njs.github.com/nginx/njs An official read-only mirror of which is updated hourly.
关于安装参考:
日常使用linux过程中,有时候我们需要从网上clone代码,大多数使用的是git,有些使用hg clone,比如说
hg clone -y install mercurial# whereis hghg: /usr/bin/hg /usr/share/man/man1/hg.1.gz# rpm -qf /usr/bin/hgmercurial-2.6.2-11.el7.x86_64
编译安装nginx,我的系统已经安装了。简单模拟下
:~/software# lsnginx-1.19.7 nginx-1.19.7.tar.gz ngx_http_proxy_connect_module# hg clone directory: njsrequesting all changesadding changesetsadding manifestsadding file changesadded 1621 changesets with 6098 changes to 463 filesupdating to branch default275 files updated, 0 files merged, 0 files removed, 0 files unresolved# lsnginx-1.19.7 nginx-1.19.7.tar.gz ngx_http_proxy_connect_module njs
重新编译增加参数:
/root/software/njs/nginx
注意这个--add-module=/root/software/njs/nginx
# cd nginx-1.19.7/# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/software/ngx_http_proxy_connect_module --with-http_realip_module --with-threads --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --add-module=/root/software/njs/nginx# make# make install
先给一个最简单的配置:
centos7 root@parallels:/usr/local/nginx/conf# cat nginx.confworker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}
centos7 root@parallels:/usr/local/nginx/conf# /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfulcentos7 root@parallels:/usr/local/nginx/conf# /usr/local/nginx/sbin/nginx -s reloadcentos7 root@parallels:/usr/local/nginx/conf# curl -I 200 OKServer: nginx/1.19.7Date: Mon, 22 Mar 2021 11:50:52 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Sun, 28 Feb 2021 06:47:57 GMTConnection: keep-aliveETag: "603b3c9d-264"Accept-Ranges: bytes
参考:
搞2个测试的js
centos7 root@parallels:~# cat /usr/local/nginx/conf/njs/utils.jsfunction version(r) { r.return(200, njs.version);}export default {version}centos7 root@parallels:~# cat /usr/local/nginx/conf/njs/example.jsfunction hello(r) { r.return(200, "Hello world!\n");}export default {hello}
centos7 root@parallels:/usr/local/nginx/conf# cat nginx.conf
worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; js_import /usr/local/nginx/conf/njs/utils.js; js_import main from /usr/local/nginx/conf/njs/example.js; server { listen 80; location = /version { js_content utils.version; } location / { js_content main.hello; } }}
注意这个路径
js_import /usr/local/nginx/conf/njs/utils.js; js_import main from /usr/local/nginx/conf/njs/example.js;
centos7 root@parallels:~# curl
0.5.2
centos7 root@parallels:~# curl
Hello world!
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #mercurialnginx #nginx njs 性能