Focus on cloud service provider activities
Notes on website operation and maintenance

Record the implementation of Nginx configuration access to static files in ECS

Nowadays, the LNMP environment configured by ECS is mostly used for WEB projects. If we want to configure Nginx to access static files, we only need to edit the configuration file of Nginx.

First, open the Nginx configuration file

Normally, this file is located in/etc/nginx/nginx. conf or/etc/nginx/conf.d/default.conf. Open the file using a text editor.

Second, add a server block in the http block to configure the static file service. Examples are as follows:

 server { listen 80; server_name example.com; root /path/to/static/files; index index.html; location / { try_files $uri $uri/ =404; } }

Explain the above configuration:

 The listen directive specifies the port Nginx listens on. In our example, we use port 80. The server_name directive specifies the domain name or IP address of the server. The root directive specifies the path to the root directory where static files are stored. The index directive specifies the default index file, which will be returned when accessing a directory. The location block defines the URL matching rules and processing logic of the request. In the example, we use the try_files directive to try to match the requested file. If the file does not exist, a 404 error is returned.

Save and close the configuration file.

Third, reload the Nginx configuration to make it effective. You can use the following commands:

 sudo systemctl reload nginx

This will reload the Nginx configuration file for your static file service to take effect.

We can place your static files in the specified root directory (for example,/path/to/static/files), and then access http://example.com/ To access these files. Please make sure to replace example.com with your actual domain name or IP address.

Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Record the implementation of Nginx configuration access to static files in ECS


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge