Skip to content

Instantly share code, notes, and snippets.

@gokman
Created December 30, 2019 11:48
Show Gist options
  • Select an option

  • Save gokman/fa1b1ab0b14afd68b9a9142f39091db3 to your computer and use it in GitHub Desktop.

Select an option

Save gokman/fa1b1ab0b14afd68b9a9142f39091db3 to your computer and use it in GitHub Desktop.
multiple angular app configuration for nginx
1. build app1 project with prod flag
ng build --prod
2. copy files under dist folder to the server
scp -r dist/app1/* {username}@{ip address of server}:/var/www/app1/
3. set base href of application (app1 works on /)
<base href="/">
4. build app2 project with prod flag
ng build --prod
5. copy files under dist folder to the server
scp -r dist/app2/* {username}@{ip address of server}:/var/www/app2/
6. set base href of application (app2 works on /app2/)
<base href="/app2/">
7. make nginx configuration in sites-available/my_app file
server {
listen 8080;
server_name {ip address of server};
location / {
alias /var/www/app1/;
try_files $uri /index.html;
}
location /app2/ {
alias /var/www/app2/;
try_files $uri /app2/index.html;
}
}
8. create symbolic link of above configuration
ln -s sites-available/my_app sites-enabled/
9. restart nginx
systemctl restart nginx
10. go app1
http://{server address}/
11. go app2
http://{server address}/app2/
@Jason-Young-AI

Copy link
Copy Markdown

Nice! It is more useful than ng build --base-href.

@gokman

gokman commented May 30, 2022

Copy link
Copy Markdown
Author

It is for production environment. You can use --base-href for development environment.

@yadavyo

yadavyo commented Dec 20, 2022

Copy link
Copy Markdown

didnt work for me. http://{server address}/app2/ is redirecting to http://{server address} so only one application is running.

@srinivasan-getstan

Copy link
Copy Markdown

same it didn't work for me with apache2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment