Angular部署Nginx子目录

1.打包

ng build –base-href /angular/part2/ –prod

注意:part2后面需要带斜线

2.nginx配置

server {
    listen 80;
    root /data/web/html/blog.joyousphper.com;
    index index.php index.html index.htm index.shtml;
    server_name blog.joyousphper.com;    
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    } 
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
        access_log off;
        expires 7d;
    }
    location /angular/part2 {
       root /data/web/html/blog.joyousphper.com/angular/part2;
       index  index.html index.htm;
       try_files $uri $uri/ /index.html =404;
    }
}

示例:

http://demo.joyousphper.com/angular/part2/

Tagged , . Bookmark the permalink.

Comments are closed.