If you want the path following the domain name to point to other directories on the local disk instead of the default web directory, you need to set up nginx directory access redirection. Application scenario: dashidan.com/image automatically jumps to dashidan.com/folderName/image. There are four ways to implement nginx directory path redirection. Modify the root mapping, redirect internally through Nginx rewrite, set up alias mapping, and implement it through nginx's permanent 301 absolute redirect. 1 nginx modifies root mapping Modifying the root mapping to redirect nginx directory access is the simplest way and is recommended. location /image { root /folderName; } 2 Access redirection through nginx rewrite internal jump Nginx configuration code example: location /image { rewrite ^/image/(.*)$ /folderName/image/$1 last; } 3 nginx alias mapping implementation Configuration example: location /image { alias /folderName/image; #Write the absolute path here} 4. Implemented through nginx's permanent 301 absolute redirect Configuration example: location /image { rewrite ^/image/(.*)$ http://dashidan.com/folderName/image/$1; } 5. Redirect page by judging URI Configuration example: if ( $request_uri ~* ^(/image)){ rewrite ^/image/(.*)$ /folderName/image/$1 last; } nginx location matching rules location matching command ~ #The wavy line indicates a regular match, case-sensitive
The priority of location matching (regardless of the order of locations in the configuration file) = Exact matches are processed first. If an exact match is found, nginx stops searching for further matches. Ordinary character matching, regular expression rules and long block rules will be given priority over query matching, which means that if the item matches, it is necessary to see if there is a regular expression match and a longer match. ^~ only matches this rule and nginx stops searching for other matches. Otherwise, nginx continues to process other location instructions. Finally, the instructions with "~" and "~*" are matched. If a corresponding match is found, nginx stops searching for other matches. When there is no regular expression or no regular expression is matched, the verbatim match instruction with the highest degree of match will be used. location = / { # Only matches "/". [ configuration A ] } location / { # Matches any request, because all requests start with "/" # But longer character matches or regular expression matches will take precedence [ configuration B ] } location ^~ /images/ { # Match any request starting with /images/ and stop matching other locations [ configuration C ] } location ~* \.(gif|jpg|jpeg)$ { # Matches requests ending with gif, jpg, or jpeg. # But all requests to the /images/ directory will be handled by [Configuration C]. [ configuration D ] } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: MySQL 5.7.10 winx64 installation and configuration method graphic tutorial (win10)
>>: WeChat applet selects the image control
MySQL variables include system variables and syst...
Table of contents Basic application of javascript...
Recently, some friends said that after installing...
Disk quota is the storage limit of a specified di...
1. Optimization of commonly used HTML tags HTML s...
Preface: As far as I know, currently CSS can only...
1. Big Data and Hadoop To study and learn about b...
This article shares the installation tutorial of ...
BackUpMysql.sh script #!/bin/bash PATH=/bin:/sbin...
Table of contents 1. Reverse the numbers 2. Get t...
Preface Readers who are familiar with MySQL may f...
Table of contents 1. Index 1.1 Concept 1.2 Functi...
VNC is a remote desktop protocol. Follow the inst...
Table of contents Overview Is the extension neces...
Sometimes, we don't want the content presente...