Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure nginx static resource server

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report