Ps: You need to restart Nginx after modifying the configuration. Command: systemctl restart nginx. Nginx configuration file: /etc/nginx/nginx.conf


1. ByDomain name/file name File typeURL format access

Application scenario: Verify the small program service domain name.

One (1) method

  • whenserverDoes not exist in the configurationlocation / { ... }At the right time.
  • Configuration example:
server { listen 80 default_server; Server_name localhost; Root /usr; /usr is the directory where the file resides. # configure this when the file is in the root directory}Copy the code

(2) the method 2

  • whenserverExists in the configuration oflocation / { ... }At the right time.
  • Configuration example:
Add: location/file name to server. File type {root /usr; /usr is the directory where the file resides. Set Expires 30d when the file is in the root directory. access_log off; }Copy the code
  • through/ File name File typeMatch with/ File name File typeRequest at the beginning.

③ Verify the configuration


2. ByDomain name/Custom/file name. The file typeURL format access

Application scenario: Set up the Nginx image server.

  • Configuration example:
location /images/ { root /usr/local/javaweb/xdxlb/; # to map/images/to/usr/local/javaweb/XDXLB/images/autoindex on; # Enable browsing function}Copy the code
  • throughlocation /images/Matches all of the/images/Request at the beginning.
  • Verify configuration:


The appendix

  • My personal blog is Messiwjy.top
  • If you have any errors or doubts, please contact [email protected]