In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to configure the Nginx static file server". Many people will encounter this dilemma in the operation of the actual case, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Basic configuration
Server {listen 80; server_name file.52itstyle.com; charset utf-8; # root directive is used to specify the base path of the file on the server root / data/statics; # location directive is used to map requests to the local file system location / {autoindex on; # index autoindex_exact_size on; # Show file size autoindex_localtime on; # display file time}}
Restart the nginx service:
Nginx-s reload
Access file service, http://file.52itstyle.com/
Set password
The htpasswd command is apache's web server built-in tool for creating and updating password files that store user names, domains, and basic user authentication.
Htpasswd (option) (parameter)
-c: create an encrypted file
-n: do not update the encrypted file, only the encrypted user name and password are displayed on the screen
-m: password is encrypted using md5 algorithm by default
-d: encrypt the password using the crypt algorithm
-p: do not encrypt the password, that is, the plaintext password
-s: encrypt the password using sha algorithm
-b: enter the user name and password on the command line instead of following the prompts
-d: deletes the specified user.
Example
Htpasswd-bc passwd.db itstyle 123456
Generate a passwd.db file in the directory with a user name of itstyle and a password of 123456. Md5 encryption is used by default.
Add the next user to the original password file
Htpasswd-b passwd.db admin 123456
Nginx configuration
Server {listen 80; server_name file.52itstyle.com; charset utf-8; root / data/share; location / {autoindex on; # Index autoindex_exact_size on; # display file size autoindex_localtime on; # display file time auth_basic "Please enter user name and password"; auth_basic_user_file / usr/local/openresty/nginx/passwd.db;}}
Restart nginx access:
Picture hotlink protection
If the images of the server are hacked by other websites, the bandwidth and access speed of the server will be affected. At this time, we need to set the hotlink protection feature for image files or video files.
Hotlink protection simply means that you can access the resource directly, but you cannot put my resource link on your own server for others to access, especially for large files such as pictures or videos. It is easy to cause the server to respond slowly.
The server {listen 80; server_name file.52itstyle.com; charset utf-8; # root directive is used to specify the base path of the file on the server. The root / data/statics; # location directive 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 the nginx service and test the picture link: http://file.52itstyle.com/nfs_c.png
This is the end of the content of "how to configure Nginx static File Server". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.