In Java development and production environments, the most commonly used web application server comes as Tomcat, although the cat can handle some static requests, such as images, html, style files, but the efficiency is not so do everyone. In a production environment, we generally use Nginx proxy server to handle static files, to improve site performance.
basic configuration
Restart Nginx services:
Access file services, http: //file.52itstyle.com/
set password
htpasswd command is the Apache Web server built-in tools for creating and updating the stored user name, domain, and basic user authentication password file.
htpasswd (option) (parameters)
- -c: Create an encrypted file;
- -n: Do not update encrypted files, only the user name encrypted password displayed on the screen;
- -m: default MD5 algorithm to encrypt the password;
- -d: CRYPT algorithm using the password encryption;
- -p: do not encrypt passwords that clear text passwords;
- -s: SHA algorithm to encrypt the password;
- -b: the command line along with a user name and password rather than prompted for a password;
- -D: delete the specified user.
Examples
Passwd.db generate a file in the directory, the user name itstyle, Password: 123456, defaults MD5 encryption.
Increase the next user in the original password file
Nginx configuration
Restart Nginx visit:
Picture anti-theft chain
If the server is hotlinking images to other sites, will affect bandwidth and access speed of the server, then we need to set the security chain function image files or video files.
Anti-hotlinking function, simply, is that you can directly access the resource, but not my resource link on your own server for others to access, especially pictures or videos of this relatively large files, very easily lead to server response slow.
server { listen 80; server_name file.52itstyle.com; charset utf-8; #root instruction group for a specified file path on the server root /data/statics; #location command is used to map the request to the local file system location ~*^.+\.(gif|jpg|png|jpeg)$ { expires 30d; valid_referers none blocked file.52itstyle.com; if ($invalid_referer) { rewrite ^/ http://www.52itstyle.com/404.jpg; } } }
Restart Nginx service, test image link: http: //file.52itstyle.com/NFS_C.png