How to configure static Resource Server by nginx
Editor to share with you how to configure nginx static resource server, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know 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.
These are all the contents of the article "how to configure static resource servers in nginx". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!