鍍金池/ 問答/Linux  HTML/ nginx 同一域名下,多靜態(tài)項(xiàng)目部署

nginx 同一域名下,多靜態(tài)項(xiàng)目部署

  1. 使用nginx部署多個(gè)靜態(tài)項(xiàng)目,通過location 來指向不同的項(xiàng)目

參考網(wǎng)上的配置:

server {
    listen       9980;
    server_name  mobile.test.icl.com;
    root /home/dev/it-cloud-lab;

    # 移動(dòng)端
    location /mobile {
       try_files $uri $uri/ /www-mobile-client-phone/dist/index.html;
    }

    # ipad端
    location  /ipad {
       try_files $uri $uri/ /www-mobile-client-ipad/dist/index.html;
    }
}

卻不能正常顯示頁面內(nèi)容

回答
編輯回答
薄荷綠

去掉中間的$uri/,你又沒配置/的情況。

server {
    listen       9980;
    server_name  mobile.test.icl.com;
    root /home/dev/it-cloud-lab;

    # 移動(dòng)端
    location /mobile {
       try_files $uri /www-mobile-client-phone/dist/index.html;
    }

    # ipad端
    location  /ipad {
       try_files $uri /www-mobile-client-ipad/dist/index.html;
    }
}
2018年9月20日 12:54
編輯回答
初念
upstream myserver{
    server XXXXXXXX; //你的公網(wǎng)ip,有端口就+上端口
}

server {
listen 80;//根據(jù)你自己的需要設(shè)置
server_name  XXXXXXXX;//你的域名
location / {
    proxy_pass http://myserver;//對(duì)應(yīng)上面的upstream
}

location /XXX{ //網(wǎng)頁路徑,根據(jù)輸入自己填寫

    //存放靜態(tài)網(wǎng)頁的路徑,根據(jù)你的存放路徑,自己填寫。例如:我的html文件存放在
    //root/home/market/dist的文件下
    alias /home/market/dist;
    
    //如果你的html文件名是index.html,就輸入index index.html index.hml,
    //若改了名字就寫到下面XXX處。
    index XXX.html XXX.hml; 
}
location /xxx{
    alias /xxx/xxx;
    index xxx.html xxx.hml;
}
2017年12月1日 23:52