分类 Linux 开发环境 下的文章

用了 letsencrypt 的免费证书,过期前忘记续,过期后使用 certbot renew 提示续签失败。

最后用下面步骤解决:

  1. 先停掉 nginx
    nginx -s stop
  2. 进行续签,由于 nginx 配置文件不在默认位置,指定了位置
    certbot renew --nginx --nginx-server-root=/usr/local/openresty/nginx/conf

这里遇到了一个问题,cdn 域名无法续签,添加了 --dry-run 参数打印详细内容(certbot renew --dry-run):

Hint: 
The Certificate Authority failed to verify the temporary nginx configuration changes made by Certbot. 
Ensure the listed domains point to this nginx server and that it is accessible from the internet.

这是因为 cdn 域名指向了供应商的机器,而不是自己的机器。
cdn 域名临时指回自己机器后重新 执行 certbot renew 后解决改问题
最后再把 cdn 域名重新指向供应商。

1. 将 nginx root 配置到 golang 项目的静态文件目录

    server {
        ...
        root /usr/share/public;
        ...
    }

2. 用 location @name 定义一个 location 用于 golang 处理

3. 用 try_files 判断 url 文件是否存在,不存在则丢给 golang 处理

4. 例子如下:

server {
    listen 80;
    server_name  xxx.sshaonan.com;
    root         /usr/share/public;
    #charset utf-8;

    index index.html index.htm;
    try_files $uri @web; 

    location @web {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host            $http_host;
        proxy_pass http://127.0.0.1:3000; 
    }
}

OpenResty 实际上相当于 Nginx + 一些模块, 自带 Lua 支持,无需编译安装 Nginx 以开启 Lua 模块

1. 安装(以下命令可能已过期,建议查看[官方安装文档]

    sudo yum install yum-utils
    sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
    sudo yum install openresty

2. 软链 openresty 中的 nginxbin 目录, 平替 nginx

    ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/bin/nginx

- 阅读剩余部分 -

1.安装

以下内容可能已过期,只用作参考,请根据最新 官方安装说明 进行安装

    $ sudo yum install -y epel-release
    $ sudo yum install -y goaccess

2. 修改 nginx 日志格式

使用 goaccess 分析 nginx 日志,需要特定格式,修改nginx.conf log_format

    #vim /etc/nginx/nginx.conf
    
    # log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                   '$status $body_bytes_sent "$http_referer" '
    #                   '"$http_user_agent" "$http_x_forwarded_for"';
    
    log_format  main  '$remote_addr - $remote_user [$time_local] requesthost:"$http_host"; "$request" requesttime:"$request_time"; '
            '$status $body_bytes_sent "$http_referer" - $request_body'
            '"$http_user_agent" "$http_x_forwarded_for"';

- 阅读剩余部分 -