生成的swagger文档页面没有用户限制 需要简单的认证后才可以访问
-
安装工具
sudo apt install apache2-utils
-
生成账号密码
htpasswd -c ./pwd user
-
配置文件
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; } }
-
针对性配置
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; }