nginx location root code example

Example 1: nginx change root directory

edit file

> sudo vim /etc/nginx/sites-available/default

server {
    listen 80;
    listen [::]:80;
    root /mnt/volume-mn1/html; # # # change this # # #
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    location / {
    try_files $uri $uri/ /index.php?$args;        
    }
    ...
}

save file

make sure file is ok

> sudo nginx -t

restart nginx

> sudo systemctl reload nginx.service

Example 2: static content nginx

server {
    root /www/data;

    location / {
    }

    location /images/ {
    }

    location ~ \.(mp3|mp4) {
        root /www/media;
    }
}

Tags:

Misc Example