B
B
BoriHagen2020-04-09 19:28:03
HTML
BoriHagen, 2020-04-09 19:28:03

How to correctly set location to a specific folder in Nginx?

I need to write in the nginx.conf file to:

server {
...
    location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css)$ {
        expires max;
    }
...
}

cache settings. Can I set the location to a specific folder and what should it look like?

An example path is /var/www/mysite.ru/data/www/mysite.ru/content/files/

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2020-04-09
@BoriHagen


In the server block, add a location block like this:
location / {
    root /data/www;
}

This location block specifies "/" as a prefix, which is compared to the URI from the request. For suitable requests, by adding the URI to the path specified in the root directive, that is, in this case, to /data/www, the path to the requested file on the local file system is obtained.

from the docks: https://nginx.org/ru/docs/beginners_guide.html

D
Dr. Bacon, 2020-04-09
@bacon

root or alias, or just specify this folder in location if the root directory is already set https://nginx.org/ru/docs/http/ngx_http_core_modul... it's not entirely clear from the question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question