By lukal6
I would like to build Angular app which will be on one Nginx (Ubuntu server) droplet and PHP api on another droplet. How I can setup my droplets in order to use Ajax calls from Angular app to my api.
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!
You have two options. Most easiest will be making single droplet. You will need Nginx + PHP.
Next option would be what you want -> Two droplets. One would require Nginx, and on second you will need Nginx/Apache + PHP. How to install LEMP on Ubuntu 16.04. On first droplet you will only need step 1, yet on second you will need step 1, 3, 4 and 5.
Be careful about Ajax limitations. Research about it, you can have problem if you want to access API on another server.
This can be solved on multiple ways and I can suggest Nginx proxy_pass. I will give idea how it can be done.
This is easy way, you need to add location for API into your nginx server block (default block is located at /etc/nginx/sites-available/default).
Example would be:
server {
listen 80 default_server;
listen [::]:80 default_server;
...
location /api {
proxy_pass http://ip_of_api_droplet;
}
...
}
Result of this would be that when you access localhost/api, you will use API on other droplet. This will help you solve SOP.
Also, if both API and Client droplet are in same datacenter, you can look into Private Networking.
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.