0xJacky / nginx-ui

Yet another WebUI for Nginx
https://nginxui.com
GNU Affero General Public License v3.0
3.58k stars 273 forks source link

Support for cache configuration #236

Open sanvu88 opened 10 months ago

sanvu88 commented 10 months ago

Caching both static and dynamic content of Nginx helps improve distribution speed for clients and reduces the load on the server.

To configure Nginx cache, I can provide a config template. However, I am encountering a small issue with configuring the cache storage directory.

proxy_cache_path /home/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=7d use_temp_path=off;

Currently, I have to manually create the directory /home/nginx/cache. However, it would be wonderful if the Nginx UI had a section for cache configuration and would automatically create the cache directory as entered.

0xJacky commented 9 months ago

What about adding a volume section in config template? Then you can define a volume in the template, and user can set the path in the UI and it will be created if the directory is not exist.

sanvu88 commented 9 months ago

In my understanding, by default, Nginx will create a directory if it doesn't exist. However, it will only create the last directory in the path. For example, if my cache path is

/home/nginx/cache

and the cache directory does not exist, Nginx will create it. However, if both the nginx and cache directories do not exist, Nginx will return an error:

[emerg] mkdir() No such file or directory) nginx

0xJacky commented 9 months ago

In my understanding, by default, Nginx will create a directory if it doesn't exist. However, it will only create the last directory in the path. For example, if my cache path is

/home/nginx/cache

and the cache directory does not exist, Nginx will create it. However, if both the nginx and cache directories do not exist, Nginx will return an error:

[emerg] mkdir() No such file or directory) nginx

Yes I understand, I want to use os.MkdirAll function, which can create a directory named path, along with any necessary parents.