Gagan Pal
Gagan Pal

Reputation: 49

How to add basic auth in specific conf if I include location/ in a global Magento conf

I include a global Magento.conf using include /etc/nginx/Magento2.conf so the location/ block is defined from the global conf above. Now if I want to add basic http auth... where and how do I add .htpasswd location in the site specific vhost config for Nginx.

Just adding the block would throw duplicate location/ block

Many thanks.

Upvotes: 0

Views: 167

Answers (2)

taur
taur

Reputation: 179

Note that rest api won't work with basic auth because one can't authorize with both basic auth and bearer token in the same request, to disable basic auth for api-requests use something like:

map $request_uri $auth_uri {
    ~^/rest/ "off";
    default "Restricted Content";
}
server {
    ...
    auth_basic $auth_uri;
    ...

Upvotes: 0

Gagan Pal
Gagan Pal

Reputation: 49

Nevermind... it was easy. Never realized you can put auth directive just after the servername directive

Example

    server {
    listen      95.216.41.220:443 ssl http2;
    server_name devdomain.com ;

    auth_basic "Restricted Content";
    auth_basic_user_file /home/.htpasswd;

Upvotes: 0

Related Questions