初玩 nginx的反向代理

得到任务要完善公司的ngix服务。加入自定义的错误页面。然后就在自己的机器的docker里装上了2个ngix的容器。一个扮演proxy,一个扮演backend app server.

第一步 为2台服务器准备2个内部的ip。然后写个简单的 docker-composer.yaml让2个ngix都能自己跑起来。里面有个小插曲,就是当nginx配置错误,或导致docker启动错误,就自己关闭了。在最后加上一个tty:true可以让进程不挂掉。

本地的host文件加入

192.168.88.18 xxxxxxx.vm
192.168.88.19 app.xxxxxxx.vm

proxy的docker-composer 这样写

version: "3.5"
services:
  # nginx server
  app:
    container_name: xxxxxxx-master
    restart: "no"    
    image: nginx:1.17
    volumes:
        - /home/hchen/private/xxxxxxx/nginx:/var/www/html:delegated
    ports: 
      - "8080:80" 
    expose:
      - "80"  
    networks:
      dh_net:
        ipv4_address: 192.168.88.18
    extra_hosts:
      - "echobot.vm:192.168.88.18"
    tty: true

networks:
  dh_net:    
    name: dh_network
    ipam:
      driver: default
      config:
        - subnet: 192.168.88.0/24
  

然后app的类似,这样写

version: "3.5"
services:
  # nginx server
  app:
    container_name: xxxxxx-app
    restart: "no"    
    image: nginx:1.17
    volumes:
        - /home/hchen/private/xxxxxx/apps:/var/www/html:delegated
    ports: 
      - "8081:80"    
    networks:
      dh_net:
        ipv4_address: 192.168.88.19
    extra_hosts:
      - "xxxxxxx.vm:192.168.88.18"
      - "app.xxxxxxx.vm:192.168.88.19"

networks:
  dh_net:    
    name: dh_network
    ipam:
      driver: default
      config:
        - subnet: 192.168.88.0/24
  

写完以后,跑起来,分别可以打开这2个站点。

第二步,把proxy改为反向代理。修改default.conf

upstream app {
   server 192.168.88.19;
}

server {
    listen       80;
    server_name  xxxxxxx.vm;
     
    location / {
       proxy_pass   http://app;
    }
     
    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    } 
}

主要就是i加上upstream 名称 ,去掉本地 /的解析,改为proxy_pass http://名称。然后reload.

这样一台简单的反向代理就搭建好了。

Hyperion Install

Update: 2020.01.06

USB已经正常工作。关于捕捉卡闪动的问题,其实解决方案就是降低分辨率。 我用倒数第二档就不错了。

另外,实验室发现最后一个灯常量,检查发现是少数了一个LED电珠,修正配置以后问题解决。

原文:

暑假里忙了一段时间的Hyperion,给自家的老电视加上背景灯效果。 然后因为图像捕捉功能有问题,就一直没有继续了。现在圣诞新年假期比较空,就重新整理一下。重新刷了SD卡。然后重新配置。

Hardware

LED 在Aliexpress上买的, 芯片是APA102系列, (颜色顺序BGR) 商家链接(Link
Layout56 (TOP) , 37 (RIGHT), 55 (BOTTOM), 34 (LEFT)
USB GrabberUTVF007 (Link)
RP Pi Zero w亚马逊买的套件 Raspberry Pi Zero W (kabellos) & Zero Essentials-Set (Link), 板子的技术细节(Link), 1G单核CPU,512内存,带WiFi和蓝牙

Software

官方镜像 2020-11-19-HyperBian-lite.imgHyperBian (解压后2GB,)直接灌入SD卡(32GB有点浪费),然后配置Wifi和SSH
镜像内包含了Hyperion.ng 已经安装在Pi上,用来提供Web界面来配置实例
默认安装没有支持这款USB Grabb er需要额外配置。 参见商家网站(Link)和 论坛(Link

主要问题是USB Grbber无法工作。(已经解决)

ssh登录显示USB设备

pi@HyperBian:/tmp $ lsusb
Bus 001 Device 002: ID 534d:0021
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

显示支持格式,则显示设备忙

pi@HyperBian:/tmp $ v4l2-ctl -list-formats-ext
VIDIOC_S_INPUT: failed: Device or resource busy
brightness 0x00980900 (int) : min=0 max=255 step=1 default=25 value=32
contrast 0x00980901 (int) : min=0 max=255 step=1 default=127 value=128
saturation 0x00980902 (int) : min=0 max=255 step=1 default=127 value=128
hue 0x00980903 (int) : min=0 max=127 step=1 default=0 value=0
gamma 0x00980910 (int) : min=0 max=50 step=1 default=0 value=0
pi@HyperBian:/tmp $

如果在Hyerion.ng内关闭USB设备就好了,显示如下

pi@HyperBian:/tmp $ v4l2-ctl -list-formats-ext
Video input set to 0 (Camera 1: Camera, ok)
brightness 0x00980900 (int) : min=0 max=255 step=1 default=25 value=32
contrast 0x00980901 (int) : min=0 max=255 step=1 default=127 value=128
saturation 0x00980902 (int) : min=0 max=255 step=1 default=127 value=128
hue 0x00980903 (int) : min=0 max=127 step=1 default=0 value=0
gamma 0x00980910 (int) : min=0 max=50 step=1 default=0 value=0

似乎是类型不对,设备被识别为Camera而不是

ioctl: VIDIOC_ENUM_FMT
Type: Video Capture

参考:

samba issue after upgrade to ubuntu 20

after ugprading to ubuntu 20, the nas is no more work. It show the error message like „Software caused connection abort“.

Why? Becuase in ubuntu 20 is samba not more installed at default. So you need to install it first.

apt-get install samba

After that you need to change the config, add support for „old samba protocol“

Add „client min protocol = CORE“ in Seciton „[global]

Thats all.

import 在typescript中的千奇百怪写法

学习angular的时候,有个使用第三方库query-string, 死活不对。老师使用的是ng8,我是ng10

老师写的是

import queryString from 'query-string';

我必须写成

import * as queryString from 'query-string';

其他时候格式都是

imprt {a, b, c } from "foo.bar"

从这里我找到了解释

https://zhuanlan.zhihu.com/p/137856912

sync the time/date in docker with host

Thanks for the tips from this post:

https://medium.com/better-programming/docker-tips-synchronize-container-timezone-with-host-machine-via-docker-compose-in-ubuntu-18-04-6f01615efc24

Two changes must be added in docker-compose.yml. First need to add TZ in enviroment, then add localtime and timezone in Volumns.

Like so

environment:
– TZ=Europe/Berlin

volumes:

- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro

upgrade nodejs from 8 to newest version in ubuntu

The default node version in Ubuntu 18 is 8.0. I need to update it.

  1. Download the newest version from https://nodejs.org/en/download/ and save it.

2. extact the file from tar and copy it to /usr/local

sudo tar –strip-components 1 -xJf node-v14.15.0-linux-x64.tar.xz -C /usr/local/

Please note, -C /usr/local/ must be the last params, otherweise it will not work, at most not work for me.

Now check version with

node -v

It should show like v14.15.0

solve winhq dependency hell in Ubuntu 18

today I need to install a new pc with xubuntu 18.04 bionic. But I got problem while installing winhq, the apt-get always says some dependency issues, and can not install it.

Finally I found the solution here:

The key is to install following package before wine:

sudo apt-get install libgnutls30:i386 libldap-2.4-2:i386 libgpg-error0:i386 libxml2:i386 libasound2-plugins:i386 libsdl2-2.0-0:i386 libfreetype6:i386 libdbus-1-3:i386 libsqlite3-0:i386

Thanks Ji M!

找到一个有意思的pdf

中国科学院武汉病毒研究所 (链接已失效)
http://www.whiov.cas.cn/tzgg_105342/201801/W020180104550979209392.pdf

中国科学动物研究院(2020.10.01)
http://www.ioz.ac.cn/xwzx/tzgg/201801/P020180112541907522850.pdf

2018年国家科学技术奖励大会 (2019-01-08)
中国蝙蝠携带重要病毒研究
http://www.cas.cn/zt/hyzt/2018gjkjjldh/zrkxj/201901/t20190108_4676163.shtml