Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to configure nginx static resource server

Shulou Source: shulou.com Published: 2022-05-31 12:30:58 09月23日 Update

Today, the editor will share with you the relevant knowledge points about how to configure the nginx static resource server. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Go to the conf directory of the nginx installation directory, modify the nginx.conf file, and add a location part of the configuration code to a server {} as follows

Root@ubuntu:/usr/local/nginx/conf# vi nginx.conf server {listen 80; server_name localhost; location / {root html; index index.html index.htm;} location / image/ {root / usr/local/myimage/; autoindex on;}}

From the above configuration, you can see that the port is 80 and the serverroomname is localhost (it is also possible to write an ip address)

Location / image/ {root / usr/local/myimage/; autoindex on;}

This configuration means that the native / usr/local/myimage/image/ directory will be accessed when you type localhost:80/image/. So to create a new / usr/local/myimage/image/ directory, and also in the html directory of the nginx installation directory, create a new image directory with the same name as image in location. Although there is nothing in this directory, we put a picture 1.jpg in / usr/local/myimage/image/, restart the nginx service, and you can access it through localhost:80/image/1.jpg.

Root@ubuntu:/usr/local/nginx/html# mkdir imageroot@ubuntu:/usr/local/nginx/html# mkdir / usr/local/myimage/image# put a photo on # root@ubuntu:/usr/local/nginx/html# cd / usr/local/myimage/imageroot@ubuntu:/usr/local/myimage/image# ls1.jpgroot@ubuntu:/usr/local/myimage/image#

Restart nginx

Root@ubuntu:/usr/local/nginx/sbin#. / nginx-s reloadroot@ubuntu:/usr/local/nginx/sbin#

Open a browser and enter server_name:80/image/1.jpg to access the static image as shown below.

These are all the contents of the article "how to configure the nginx static Resource Server". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Directory configuration knowledge article static service server resource content picture face input different big code can be passed at the same time address most of it Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info MySQL Linux Huawei