nginx简单认证访问

生成的swagger文档页面没有用户限制 需要简单的认证后才可以访问

  1. 安装工具
    sudo apt install apache2-utils

  2. 生成账号密码
    htpasswd -c ./pwd user

  3. 配置文件

    server {
    listen       80;
    server_name  local.server.com;
    **auth_basic "User Authentication";
    auth_basic_user_file /etc/nginx/pwd;**
    location / {
        root   /data/www;
        index  index.html;
    }
    }
  4. 针对性配置

    location ~ /.*/swagger-ui.html.* {
      #密码登录
      auth_basic "接口文档";
      auth_basic_user_file /opt/nginxpwd;
      # 不同的路径进入到不同地址,还不知道怎么改成一个通配符,自动填充
      if ( $uri ~ /smsapi/.* ) {
        proxy_pass http://smsapi;
      }
      if ( $uri ~ /find/.* ) {
        proxy_pass http://find;
      }
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

相关资料

简单实现 nginx 用户登录认证
nginx 拦截 swagger 登录

gitlab重置root的密码


-sh-4.2$ gitlab-rails console production
-------------------------------------------------------------------------------------
 GitLab:       12.0.3 (08a51a9db93)
 GitLab Shell: 9.3.0
 PostgreSQL:   10.7
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.1.7)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):004:0> user.password=12345678
=> 12345678
irb(main):005:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 60439440-6443-46d1-acda-e29172be146a) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f09e949b958 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):006:0> exit
-sh-4.2$ exit
[root@qas-k8s-gitlab gitlab]# gitlab-ctl restart
ok: run: alertmanager: (pid 43507) 0s
ok: run: gitaly: (pid 43523) 0s
ok: run: gitlab-monitor: (pid 43542)
————————————————

原文地址