<html><head></head><body><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">I would like to hide a backend API REST server from public view and have it accessed from frontend web server locally/internally. Is this possible? Below are my setup and configs: <br><div><div id="ydp904295bdyiv4988927207"><div><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div><span><br>angular/nodejs frontend app, say it is "mysite.com" running on server at 127.0.0.1:51910<br><br>nodejs backend app, say it is "api.anothersite.com" running on server at 127.00.0.1:50010<br><br>nginx(open source) listens for the server_name/domain and does a proxy_pass to the host/port listed above <br><br>I currently can communicate back and forth with GET and POST requests and JSON responses.<br><br>So far everything is great.<br><br>However, beside just using CORS, I would now like to secure/hide "api.anothersite.com" from the public and just allow "mysite.com" to access 127.0.0.1:50010 internally instead of "api.anothersite.com" <br><br>Can this be done via nginx?<br><br> server {<br> server_name api.anothersite.com;<br> <br> listen 443 ssl;<br> ssl_certificate /etc/letsencrypt/live/anothersite.com/fullchain.pem; <br> ssl_certificate_key /etc/letsencrypt/live/anothersite.com/privkey.pem; <br> include /etc/letsencrypt/options-ssl-nginx.conf; <br> ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;<br> <br> location / {<br> #allow xx.xx.xx.xx;<br> #allow 127.0.0.1;<br> #deny all;<br> proxy_pass http://127.0.0.1:50010;<br> <br> proxy_http_version 1.1;<br> proxy_set_header Upgrade $http_upgrade;<br> proxy_set_header Connection 'upgrade';<br> proxy_set_header Host $host;<br> proxy_cache_bypass $http_upgrade;<br> }<br> }<br><br> server {<br> server_name mysite.com www.mysite.com;<br> <br> location / {<br> <br> proxy_http_version 1.1;<br> proxy_pass http://localhost:51910;<br> proxy_set_header Upgrade $http_upgrade;<br> proxy_set_header Connection 'upgrade';<br> # proxy_set_header Host $host;<br> proxy_set_header Host mysite.com;<br> proxy_cache_bypass $http_upgrade;<br> proxy_pass_request_headers on;<br> }<br> <br> #error_page 404 /404.html;<br> <br> # redirect server error pages to the static page /50x.html<br> #<br> error_page 500 502 503 504 /50x.html;<br> location = /50x.html {<br> root /usr/share/nginx/html;<br> }<br> <br> listen 443 ssl; <br> ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; <br> ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; <br> include /etc/letsencrypt/options-ssl-nginx.conf; <br> ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; <br> }<br> <br> server {<br> if ($host = www.mysite.com) {<br> return 301 https://$host$request_uri;<br> } <br> <br> if ($host = mysite.com) {<br> return 301 https://$host$request_uri;<br> } <br> <br> listen 80;<br> server_name mysite.com www.mysite.com;<br> return 404; <br> }</span><br></div></div></div></div></div>
</div><div id="ydp904295bdyahoo_quoted_2800245339" class="ydp904295bdyahoo_quoted">
</div></div></body></html>