dqu92800 2019-01-28 22:55
浏览 65

使用HTTP基本身份验证时,Nginx重定向循环

I'm trying to setup basic authentication for all of my site, but I'm getting a redirect loop when I try to enable it. Current config works, but when I add

auth_basic           "Secured";
auth_basic_user_file /var/www/*****/.htpasswd;

under location / {

it redirects endlessly to mysite.com/login and fails. mysite.com/login is the login page for the script I'm using, but it is not supposed to redirect there upon visiting the homepagepage and it does not do so normally. I am not sure if something in my script is causing the redirect loop, or my nginx config but I would like to figure a way to enable basic HTTP authentication.

Any ideas would be most appreciated, thank you.

server {
    server_name  ***** www.*****;

    # note that these lines are originally from the "location /" block
    root   /var/www/******/public;

    location / {
        try_files $uri /index.php$is_args$args;
  }

    location ~ ^/index\.php(/|$) {
        include fastcgi.conf;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/*****/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/*****/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.*****) {
        return 302 https://$host$request_uri;
    } # managed by Certbot


    if ($host = *****) {
        return 302 https://$host$request_uri;
    } # managed by Certbot


    listen   80;
    server_name  ***** www.*****;
    return 404; # managed by Certbot


}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?