Sometimes you need to access some static resources on the server, such as mounting images on other devices to a local directory, and the local directory is not in the nginx root directory. At this time, you need to simply do a directory mapping to solve it. For example, if you want to access the system directory /image_data/2016/04/29/10/abc.jpg through the browser upload/2022/web/abc.jpg, you need to add a location rule under the corresponding server {} in nginx.conf. The configuration is as follows: location /image/ { root /; rewrite ^/image/(.*)$ /image_data/$1 break; } location /image/ sets the server to intercept requests containing /image/. The actual range is determined by the actual situation. root /; sets the root directory to be used. rewrite is the real jump rule. It sets the request starting with image to jump to the root directory starting with /image_data. The following parameters are added intactly, thus realizing the directory mapping. Using the above rules, you can easily map to multiple local directories for static access. After saving, use ./nginx -s reload to reload the configuration file and access the specified URL. In addition, you can also flexibly configure precise proxies, such as proxying a certain access path. For example, when we access http://ip/abc/bcd/123.ico, we map it to /web/host1/123.ico, then you can configure the following rules: location /abc/bcd/123.ico { root /; rewrite ^/abc/bcd/123.ico$ /web/host1/123.ico break; } The above implements precise path proxy. Note that /web/host1 is a file system path, not a virtual directory of the web host, because the root setting above is the root directory. If root is not specified, the global root value specified in the previous server block will prevail. The scope of the attributes in each location block is only within this block. In addition, multiple proxy paths can be accessed through the real web path or through the proxy path, so that the proxy can be set according to different business needs. Then nginx itself can realize many practical and easy-to-use functions. 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 sets the specified user database view query permissions
>>: MySQL login and exit command format
<!--[if IE 6]> Only IE6 can recognize <![...
1》Be good at web design 2》Know how to design web p...
Download image docker pull mysql:5.7 docker pull ...
Canvas is a new tag in HTML5. You can use js to o...
FIFO communication (first in first out) FIFO name...
Table of contents 1. Overview 1.1 What is strict ...
This article shares the specific implementation c...
This article uses an example to describe the simp...
I just tried it on IE6, and it does show the toolb...
Preface In MySQL, InnoDB belongs to the storage e...
When making some pages, in order to make the page...
This article shares the specific code for JavaScr...
An absolute URL is used to represent all the conte...
1.watch listener Introducing watch import { ref, ...
There are two types of web page box models: 1: Sta...