分类 其他 下的文章

xcode 更新之后需要运行 xcode-select --install 更新 CommandLineTools

但是更新完以后,没生效。运行 git 命令的时候还是提示更新

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

这时候只需要执行以下命令即可

sudo xcode-select -s /Library/Developer/CommandLineTools

安装

curl https://get.acme.sh | sh -s [email protected]

使用域名解析商提供的 api 自动添加 txt 记录完成验证

以阿里 dns 为例,其他服务商参考 How to use DNS API

export Ali_Key="key"
export Ali_Secret="secret"
acme.sh --issue --dns dns_ali -d example.com -d *.example.com

copy 证书

mkdir -p /etc/nginx/certs/example.com
acme.sh --install-cert -d example.com --key-file /etc/nginx/certs/example.com/key.pem --fullchain-file /etc/nginx/certs/example.com/cert.pem

使用证书

在 nginx 443 端口的配置中添加如下配置:

ssl_certificate /etc/nginx/certs/example.com/cert.pem;
ssl_certificate_key /etc/nginx/certs/example.com/key.pem;

并把 80 的请求跳转到 443,上述配置可以单独列在一个文件中,需要的地方引入即可

原文

I did a bit more research and seem to have used better key words because I found my solution now. I wanted to share the solution with everyone, in case someone else may ever need it.

Create folder for configuring docker service through systemd

mkdir /etc/systemd/system/docker.service.d

Create service configuration file at /etc/systemd/system/docker.service.d/http-proxy.conf and put the following in the newly created file

[Service]
# NO_PROXY is optional and can be removed if not needed
# Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port
# For Proxy server which require username and password authentication, just add the proper username and password to the URL. (see example below)

# Example without authentication
Environment="HTTP_PROXY=http://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"

# Example with authentication
Environment="HTTP_PROXY=http://username:password@proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"
Reload systemctl so that new settings are read

sudo systemctl daemon-reload

Verify that docker service Environment is properly set

sudo systemctl show docker --property Environment

Restart docker service so that it uses updated Environment settings

sudo systemctl restart docker

Now you can execute the docker-compose command on your machine without getting any connection refused error messages.

背景

某 spring 服务使用 nginx 反向代理(下文称为 nginx-a),对外提供服务,并且在 nginx 上配置了 gzip on

后来由于某些原因,需要在 nginx 前面再加一层 nginx 做反向代理(下文称为 nginx-b),并且没有开启 gzip,因为已经在 nginx-a 开启了 gzip,无需开启两次

问题

加上 nginx-b 之后发现,浏览器访 nginx-b 问的时 gzip 失效了,于是又把域名指向 nginx-a,发现 gzip 却是生效的。

结论

排查之后发现是由于 nginx 作为反向代理服务器(nginx-b),会给后端服务发送一个 header Via: nginx,并且 nginx 作为 upstream(nginx-a)回检查 header 中的 Via,默认配置下如果设置了这个 header,nginx 返回的内容就不做 gzip 压缩,所以访问 nginx-b 的时候 gzip 失效了。

解决办法

只需要在 nginx-b 的配置里加上 gzip_proxied: any,表示任何时候返回的内容都做 gzip,具体介绍见 nginx 官网文档

参考文献: