如何在ubuntu服务器16.04中创建保护文件夹?

我的太阳

DirectAdmin panelprotectAdmin文件夹创建文件夹中,但是我需要protect在Ubuntu服务器16.04中为文件夹创建而不使用DirectAdmin panel

例如在DirectAdmin面板中:

路径:/ admin

档案:.htaccess

AuthGroupFile /dev/null
AuthType Basic
AuthUserFile /home/user/domains/domain.com/.htpasswd/public_html/administrator/.htpasswd
AuthName "admin"
require valid-user

路径/home/user/domains/domain.com/.htpasswd/public_html/administrator/.htpasswd

admin:$apr1$Zbp5WV.h$wmBNMkeSuUd./eL9OFwxX.

图片:

在此处输入图片说明

......

现在如何protect在Ubuntu服务器16.04中为文件夹创建文件?

乔治·乌多森

有两种方法可以执行此操作:

  1. 使用命令htpasswd,并且

  2. 使用.htaccess档案

选项1:

  1. htpasswd首次使用该命令时,我们将如下所示使用它:

    sudo htpasswd -c /etc/apache2/.htpasswd sammy
    
    # you wil be asked for password for user sammy
    # content of .htpasswd would be
    # sammy:$apr1$lzxsIfXG$tmCvCfb49vpPFwKGVsuYz.
    # another_user:$apr1$p1E9MeAf$kiAhneUwr.MhAE2kKGYHK.
    
  2. 对于其他用户,则忽略了-c争论

    sudo htpasswd /etc/apache2/.htpasswd another_user
    
  3. 配置apache来检查此文件(.htpasswd):

    一种。打开有关域的虚拟主机文件:

    sudo nano /etc/apache2/sites-enabled/000-default.conf
    
    
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
            <Directory "/var/www/html/MyDomain/protect_folder">
                    AuthType Basic
                    AuthName "Restricted Content"
                    AuthUserFile /etc/apache2/.htpasswd
                    Require valid-user
            </Directory>
    </VirtualHost>
    

    b。重新启动Apache:

      sudo service apache2 restart
    

选项2:使用 .htaccess file

  1. 在/ var / www目录中找到包含文档根目录的块。通过将该块内的AllowOverride指令从“ None”更改为“ All”来打开.htaccess处理

    sudo nano /etc/apache2/apache2.conf
    
    <Directory /var/www/>
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
    </Directory>
    
      # save and close
    
  2. .htaccess文件添加protect folder

    sudo nano /var/www/html/.htaccess
    
    # Add the following
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
    
  3. 重新启动Apache:

    sudo service apache2 restart
    

笔记:

  1. 优势.htpasswd file

    Apache不会在涉及目录的每个请求上重新读取这些文件,这有助于提高性能。

  2. 优势.htaccess file

    如果您不能修改,Virtual host file这是正确的选择

  3. 您不必/etc/apache2/sites-enabled/000-default.conf使用可能已创建的任何虚拟主机

  4. 这是由VPS您控制的,对于共享主机设置,它将取决于主机,通常是自动共享主机的客户服务寻求建议

来源:

https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-apache-on-ubuntu-14-04

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在C#中的服务器PC上创建文件夹

如何在Azure Logic应用中的SFTP服务器上创建文件夹?

如何在Ubuntu服务器上保护后缀

如何在 Bonita Web 服务器中创建一个新文件夹?

从Web服务器的受保护文件夹中获取字符串

如何在Linux Web服务器上创建快捷方式文件夹?

如何在每位用户的Ubuntu服务器上创建远程桌面服务器

如何在 Ubuntu 服务器中设置全球 IP?

如何在我的 ubuntu 服务器中运行 .cpp?

如何在ubuntu 16.04.1服务器中添加NIC?

如何在ubuntu服务器中配置多个代理

如何在Ubuntu服务器中配置DNS设置?

如何在VirtualBox中全屏使用Ubuntu服务器?

如何在Ubuntu中安装绑定DNS服务器和Apache Web服务器?

如何检查ubuntu服务器12.04中的文件夹权限?

如何在 VSCode SSH TARGETS 中为服务器设置多个文件夹?

如何在ubuntu服务器中重新创建.Trash文件

在IIS Web服务器中,如何在根目录中创建一个文件夹来承载下载文件?

如何保护Ubuntu服务器安全?

如何在特定文件夹中创建nuspec文件?

如何在每个文件夹中创建文件?

为什么在服务器文件夹中的main.js文件外部创建集合?

如何在CMD中目录的每个文件夹中递归创建子文件夹

如何在用户选择的根文件夹中创建包含某些子文件夹的文件夹?

如何保护laravel存储文件夹?

如何保护Laravel Storage文件夹

如何在SilverStripe中的主题文件夹内创建公用文件夹

如何在java中的文件夹内创建文件夹

如何在JavaFX中使用treeview在主文件夹中创建许多文件夹?