In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to configure the static file server in Nginx. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
In Java development and production environment, the most commonly used web application server is Tomcat, although this cat can also handle some static requests, such as pictures, html, style files, etc., but the efficiency is not so satisfactory. In a production environment, we generally use Nginx proxy servers to process static files to improve website performance.
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: delete 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 article on "how to configure the static file server in Nginx". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.