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
Date type differences and uses MySQL has five dat...
CSS matches multiple classes The following HTML t...
This article summarizes some simple principles of...
This article shares the tutorial of MySql install...
Preface The most common task after we install a L...
In development, it is often necessary to cache th...
Table of contents What is Docker Client-side Dock...
Table of contents 1. Knowledge description of the...
Disable swap If the server is running a database ...
In the process of writing HTML, we often define mu...
1. --cpu=<value> 1) Specify how much availa...
Table of contents Introduction to NIS Network env...
1. Install JDK 1.1 Check whether the current virt...
Method 1 Copy code The code is as follows: documen...
<br />Hello everyone! It’s my honor to chat ...