nginx root alais
时间: 2023-09-08 08:09:08 浏览: 108
详解Nginx静态服务配置(root和alias指令)
Nginx allows you to define root and alias directives in its configuration to handle file serving.
The `root` directive is used to specify the root directory for a location block. It sets the base directory against which location directives are evaluated. For example:
```
server {
...
root /var/www/html;
...
}
```
In this case, requests to this server block will be served from the `/var/www/html` directory.
On the other hand, the `alias` directive is used to define a location that is different from the document root directory. It is commonly used when you want to serve files from a specific directory but want to hide the actual path. For example:
```
server {
...
location /images/ {
alias /var/www/images/;
}
...
}
```
In this case, requests to `/images/` will be served from the `/var/www/images/` directory, but the URL will not expose the actual directory structure.
Both `root` and `alias` can be useful for serving static files or handling different file serving requirements in Nginx.
阅读全文