简体   繁体   中英

Nginx - set global auth_basic

I would like to set the auth_basic globally for all the projects with nginx.

It works well by setting in on every project conf with:

auth_basic "DEV restricted access";
auth_basic_user_file /var/www/passwd;

In order to avoid this to be forgot for new projects, I would like to set this globally. Is it possible?

According to the manual , auth_basic can be configured globally by placing the commands within the http block.

Depending on your particular flavour of OS, start with the master nginx.conf configuration file, and find the http { ... } section or possibly an auxiliary configuration file which is pulled into it using an include statement.

Create file:

/etc/nginx/conf.d/pick-your-name.conf

and put there this piece of text:

auth_basic "DEV restricted access";
auth_basic_user_file /var/www/passwd;

Works the same as placing it straight into nginx.conf but keeps your configuration clean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM