linux nginx 同时隐射网站和本地目录 以及 alias root的区别

来源:互联网 发布:蔬菜水果配送软件 编辑:程序博客网 时间:2024/06/01 08:12

参考下面

server {

    listen       80;
    server_name  192.168.9.89;
    location / {
        root   /home/www/wwwroot/mirrors;
        index  index.html index.htm index.php default.php;
    }


    location /archlinux/ {
        proxy_pass   http://tel.mirrors.163.com/archlinux/;
    }
    location /centos/ {
        proxy_pass   http://tel.mirrors.163.com/centos/;
    }
    location /fedora/ {
        proxy_pass   http://tel.mirrors.163.com/fedora/;
    }
    location /freebsd/ {
        proxy_pass   http://tel.mirrors.163.com/FreeBSD/;
    }
    location /gentoo/ {
        proxy_pass   http://tel.mirrors.163.com/gentoo/;
    }
    location /ubuntu/ {
        proxy_pass   http://tel.mirrors.163.com/ubuntu/;
    }
    location /ubuntu-releases/ {
        proxy_pass   http://tel.mirrors.163.com/ubuntu-releases/;
    }
}







好长时间都没搞清nginx的root路径:


location /img/ {
    alias /var/www/image/;
}
#若按照上述配置的话,则访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件
location /img/ {
    root /var/www/image;
}
#若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件。] 


alias是一个目录别名的定义,root则是最上层目录的定义。


一直以为root是指的/var/www/image目录下,应该 是 /var/www/image/img/ 


还有一个重要的区别是alias后面必须要用“/”结束,否则会找不到文件的。。。而root则可有可无~~
1 0