天天看點

nginx配置多個前端項目

實作通過域名+項目名的方式通路不同前端項目

兩個項目的目錄分别是:root/www/   和   root/jxiaoshuai-blog-demo/   下面

nginx配置

用了root 和alias兩種方式

nginx配置多個前端項目
location / {
   root /root/jxiaoshuai-blog-demo/;
   index index.html index.htm;
}


location /www {
    root /root/;
    index index.html index.htm;
}
#改成location /www 我們浏覽器通路路徑也就變為域名+www+路由:http:www.baidu.com/www/#/login


#測試alias
#location /www {
#    alias /root/www/;
#    index  index.html index.htm; 
#}
           

差別

root配置 :nginx直接轉發至 root後面位址+location 後面位址

alias配置: nginx直接轉發至 alias的位址,不會加上location後的内容

alias配置最後一定要 “/” 結尾 ,root随意