Включить basic_auth для домена в cloud66 nginx CustomConfig

Зайти на сервер или все сервера кластера приложения в cloud66 по ssh. Создать папку и конфиг htpasswd:

apt-get install apache2-utils -y
mkdir /current/
htpasswd -cb /current/.htpasswd my_login my_password

В панельке cloud66 зайти в настройки приложения «Configuration» -> «Configuration Files», перейти на вкладку «NGINX». Найти в шаблоне CustomConfig для nginx следующие строчки:

{% if red_www == 0 %}
    server_name             {{ upstream.traffic_matches }};
{% endif %}

Выше перед ними вставить следующее условие:

#######################
# Custom_my_auth_basic
#######################
        {% for domainname in upstream.traffic_matches %}
            {% if domainname == 'domain.com' %}
                auth_basic "Restricted";
                auth_basic_user_file /current/.htpasswd;
            {% endif%}
        {% endfor %}
##########################
# end Custom_my_auth_basic
##########################

domain.com — заменить на доменное имя Вашего приложения.

Применимо в том случае, если в настройках service.yml Вы указали домен в traffic_matches

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>