2017-05-04 41 views
1

我想實現這個目標nginx的配置:多角度2個應用程序和/ API nginx的

mydomain.com/api  should serve the php API 
mydomain.com/login  should serve an angular 2 app 
mydomain.com/dashboard should serve another angular 2 app 

我下面張貼的nginx.conf工作,除了這樣的好(這是問題我需要幫助固定):

當用戶訪問路徑的角像mydomain.com/dashboard/forms那麼該URL重寫這樣mydomain.com/dashboard/dist/forms

以下是代碼樹:

├── mydomain.com 
│   ├── app   // slim project 
│   │   └── ... 
│   ├── public 
│   │   ├── dashboard // anuglar project 
| | | └── dist 
│   │   └── login  // angular project 
| |  └── dist 

,這裏是服務器塊使用:

server { 

    listen 80; 
    server_name mydomain.com; 

    error_log /home/test/code/mydomain.com/error.log; 
    access_log /home/test/code/mydomain.com/access.log; 
    root /home/test/code/mydomain.com/public/; 

    sendfile on; 
    rewrite_log on; 
    include /etc/nginx/mime.types; 

    gzip on; 

    location ~ ^/(assets|bower_components|scripts|styles|views) { 
    expires  31d; 
    add_header Cache-Control public; 
    } 

    ############################################################################ 
    #        D A S H B O A R D 
    ############################################################################ 

    location /dashboard/ { 
    alias /home/test/code/mydomain.com/public/dashboard/dist/; 
    try_files $uri $uri/ /index.html =404; 
    } 

    ############################################################################ 
    #        L O G I N 
    ############################################################################ 

    location /login/ { 
    alias /home/test/code/mydomain.com/public/login/dist/; 
    try_files $uri $uri/ /index.html =404; 
    } 

    ############################################################################ 
    #         A P I 
    ############################################################################ 

    location ~ ^/api/(.*)$ { 
    alias /home/test/code/mydomain.com/public; 
    try_files $1 $1/ @php; 
    index index.php; 
    } 

    location @php { 
    fastcgi_split_path_info ^(/api)(/.*)$; 
    fastcgi_pass localhost:9000; 
    fastcgi_index index.php; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME /home/test/code/mydomain.com/public/index.php; 
    fastcgi_param REQUEST_URI $fastcgi_path_info; 
    fastcgi_read_timeout 900; 
    } 
} 

我應該改變,使「/ DIST」沒有得到書面的網址是什麼?

回答

1

配置文件實際上很好。問題是用--base-ref/dashboard/dist /而不是普通/儀表板構建角度應用程序/

相關問題