Sometimes do not want a directory to be accessed, so to add a password to protect, the previous use of Apache seems very simple to achieve directory encryption. I used the Nginx, used for so long Nginx really did not try to encrypt ...
Reference to some information, and then found that this can be: (Debian system, Configuration "# ..." means that there are other configurations)
1. Configure the Web site (if yousite.com is placed in/home/www, then encrypt the Ooxx directory)
Copy Code code as follows:
server {
Listen 80;
server_name yousite.com;
root/home/www;
Index index.php index.html;
Location ^~/ooxx/{
Auth_basic "Authorized users only";
AUTH_BASIC_USER_FILE/HOME/.HTPASSWD;
}
#......
}
2. Install Apache 2 tool (requires HTPASSWD command)
Copy Code code as follows:
Apt-get Install Apache2-utils
3. CD to/home directory (other directories are OK, but pay attention to auth_basic_user_file consistent with above), use HTPASSWD to generate user name and password
Copy Code code as follows:
HTPASSWD-BDC. htpasswd Username Password
(note: the generated. htpasswd file may need to be set to run by the Nginx user)
In this way, you direct access to Http://yousite.com/ooxx will prompt you to enter the user and password, input just use htpasswd set the user and password can go in!
But then you will find that direct access to the PHP file will become a download rather than a run-------
Checked the Nginx to the PHP configuration:
Copy Code code as follows:
Location ~ \.php$ {
Include/etc/nginx/fastcgi_params;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
}
That's right.
This is how I solved it: in the location ^~/ooxx/{...}, add a section of PHP configuration, become
Copy Code code as follows:
server {
Listen 80;
server_name yousite.com;
root/home/www;
Index index.php index.html;
Location ^~/ooxx/{
Location ~ \.php$ {
Include/etc/nginx/fastcgi_params;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
}
Auth_basic "Authorized users only";
AUTH_BASIC_USER_FILE/HOME/.HTPASSWD;
}
#......
}
Finish the work, please refer to Nginx Official document, I casually play (anyway is successful).
Side Note: If you remove the ^~ of the location ^~/ooxx/, you will have to enter a password to access the directory, but you can access the file directly, note.