ubuntu - Server setup: Subdomain or different port for API and single or multiple ssl certificates for a docker, nginx, web and api setup? -
i using digital ocean
ubuntu 15.10
server
. have 3 docker containers
: nginx
, web
(for angular 2
app), , rails
rails api
.
i planning on setting nginx
configuration file follows:
port 443
proxy passed
nginx
web
app.
after i'm bit confused on how should allow outside access rails api
? should make rails api
accessible through subdomain
, if how? or should use same domain web
app although different port
?
next question need 1 ssl certificate
outside world connecting nginx
layer? or need 1 ssl certificate
web application
, 1 ssl certificate
rails api
?
you can use nginx load balancer both endpoints. should fine:
upstream web { server webcontainer1:8080; server webcontainer2:8080; } upstream api { server apicontainer1:5000; server apicontainer2:5000; } server { <your_server_directives> ... location /api { proxy_pass http://api; } location / { proxy_pass http://web; } }
you subdomain separate nginx. in case setup server
directive , virtual hosting on same port or api specific port like:
upstream api { server apicontainer1:5000; server apicontainer2:5000; } server { listen 5500; server_name api.mydomain.com; location /api { proxy_pass http://api; } }
in first scenario, yes, can 1 ssl certificate api , web on 1 port (one domain name). in second scenario, you'd need wildcard certificate or 2 certificates, 1 main web (yourdomain.com) , api (api.yourdomain.com).
it worth noting second scenario can run annoying csrf issues because ssl pages not allow xhr requests outside current domain. can second subdomain api, end needing 3rd proxy in nginx config proxy yourdomain.com/api
api.yourdomain.com
.
Comments
Post a Comment