Configuring static nginx access local resources

Here to talk about how to use nginx as a static resource server under windows,

1, modify the config directory, configuration file, basically all of the configurations in here to do,

 

 2, the main configuration parameters are as follows, a number of independent parameters I directly removed, attention, which may be a plurality of location, so that you can specify the relative path to facilitate the subsequent operation and maintenance and management based on business needs,

server {

listen 80; #nginx listening port
server_name localhost; # intercepted User Access

#charset koi8-r;

#access_log logs/host.access.log main;

Under static html # access the local absolute path
LOCATION / {
#root html;
the root D: / Tools / Nginx / 2 / HTML1;
index index.html index.htm;
}

# A picture in the access path to access the local absolute path splicing upload
LOCATION / upload / {
Alias D: / Tools / Nginx / 2 / image1 /;
autoindex ON;
}

# Access path splice / pages with an absolute static html access the local path
LOCATION / pages / {
Alias D: / Tools / Nginx / 2 / HTML1 /;
autoindex ON;
}

# Fine configuration-related static resource parameters to optimize access static resource files
LOCATION ~ * \ (GIF | JPG | jpeg | PNG) $ {..
The Expires 24h;
root D: / Tools / nginx / 2 / image1 /; # specify the picture storage path
proxy_store ON;
proxy_temp_path D: / Tools / nginx / 2 / image1 /; # image access path
proxy_redirect OFF;
proxy_set_header Host 127.0.0.1;
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40K;
proxy_buffers 320K 40;
proxy_busy_buffers_size 640K;
proxy_temp_file_write_size 640K;
IF (-e $ request_filename!)
{
proxy_pass HTTP: //127.0.0.1; # default port 80
}

}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

 

3, under normal circumstances, double-click the exe file to start, visit localhost: 80, nginx nginx default back to find the html below index.html,

 

 The first configuration, using the local absolute path, a static html put under your directory, here is my path: D: / tools / nginx / 2 / html1;
so configured as follows:

Under static html # access the local absolute path
LOCATION / {
#root html;
the root D: / Tools / Nginx / 2 / HTML1;
index index.html index.htm;
}

 

Then, in the black window: nginx -s reload this: you can see the page is accessed under its own directory,

 

 4, of course, in order to ensure a certain degree of security, also can be spliced ​​on a string in the address to access, such as I have here added a page, the overall configuration is as follows,

# Access path splice / pages with an absolute static html access the local path
LOCATION / pages / {
Alias D: / Tools / Nginx / 2 / HTML1 /;
autoindex ON;
}

Visit again and still have access to the html in that directory,

 

 

5, access to pictures, and here I used two ways, first and configure access static html similar, using an absolute path access,

# A picture in the access path to access the local absolute path splicing upload
LOCATION / upload / {
Alias D: / Tools / Nginx / 2 / image1 /;
autoindex ON;
}

 

Browser to access it, you can see that, you can successfully access to picture,

 

 

Look at the second way, usually in order to optimize the static resource access nginx, we need to do some tuning parameter configuration, such as the picture compression, caching, add a security check user name and password, etc., can be configured directly, as follows , the inside can continue to add other parameters, you can access to relevant information for learning research,

# Fine configuration-related static resource parameters to optimize access static resource files
LOCATION ~ * \ (GIF | JPG | jpeg | PNG) $ {..
The Expires 24h;
root D: / Tools / nginx / 2 / image1 /; # specify the picture storage path
proxy_store ON;
proxy_temp_path D: / Tools / nginx / 2 / image1 /; # image access path
proxy_redirect OFF;
proxy_set_header Host 127.0.0.1;
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40K;
proxy_buffers 320K 40;
proxy_busy_buffers_size 640K;
proxy_temp_file_write_size 640K;
IF (-e $ request_filename!)
{
proxy_pass HTTP: //127.0.0.1; # default port 80
}

}

Then we try to access it, you can see, you can still succeed through access to picture this way, because we do a path proxy configuration parameters in the configuration inside,

 

 

Summary: a scenario here that, in some large electricity provider website, there are some details on the product page, data aggregation needs of a variety of different dimensions, such as a picture like this,

 

 

We try, for the first time to enter a product detail page, if speed is not very good, then you will find loads of speed is relatively slow, it is said, in order to solve this problem, but many architects on the issue began to prefer to use dimension data aggregation + + cache static pages comprehensive solution to this problem, in which static template technology here has been very good application, as to the details of which we can look for information about the study, the main idea is to contain a large amount of data to be rendered rendered static template pages in advance, can greatly enhance the access speed of access through nginx according to the relevant service parameters, of course, in order to improve the overall page rendering speed, static pages just one aspect of technology, behind architecture idea is very worthy of our study and explore!

----------------
Disclaimer: This article is CSDN blogger "mysterious onion" in the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and link this statement.
Original link: https: //blog.csdn.net/zhangcongyi420/article/details/89216867

Guess you like

Origin www.cnblogs.com/cnblog-long/p/11690234.html