By aloksguha
Hi Folks,
I am new to digital ocean platform and nginx, I have setup a droplet which serves an angular app seamlessly, however I want to serve multiple angular apps from one digital-ocean droplet based on URL/path.
for an example
abc.com/app1 -----> ~/app1/index.html abc.com/app2 -----> ~/app2/index.html
and so on.
Please refer following configuration I have for my sites-available/abc.com
server {
root /home/alok/abc-web;
index index.html index.htm index.nginx-debian.html;
server_name abc.one www.abc.one;
try_files $uri $uri/ /index.html;
location /app1/ {
alias /home/alok/abc-web/app1/dist/;
try_files $uri /index.html;
}
location /app2/ {
alias /home/alok/abc-web/app2/dist/;
try_files $uri /index.html;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/abc.one/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/abc.one/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = abc.one) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name abc.one www.abc.one;
return 404; # managed by Certbot
}
I have replaced abc.com with actual domain name I used.
I understand its more of an Nginx config issue than a digital-ocean droplet issue.
Thanks in advance.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
I think that the Ningx config looks good, you just need to update the locations a little bit to:
location /app1/ {
alias /home/alok/abc-web/app1/dist/;
try_files $uri /app1/index.html;
}
location /app2/ {
alias /home/alok/abc-web/app2/dist/;
try_files $uri /app2/index.html;
}
Note that after each Nginx config change, you need to restart/reload the Nginx service.
Let me know how it goes! Best, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.