I have got 2 applications:
Nodejs application and Angular application.
I would like to host them both on the same Linux server (Linode).
Also I have a DNS record for example : forexample.com.
I would like that when I navigate to api.forexample.com it will navigate inside the linux server to the Angular application, and I should see the angular pages.
The nodejs application is a API application which I would like other people to make all the HTTP requests to api.forexample.com/api.
So the question is how to make the navigation inside the linux server?
Generally speaking to run multiple applications on a server. First you need to add an A record on your DNS record for api.forexample.com
Then you can use nginx to handle the two applications. The way it will work is that each application will run locally on its own port and nginx will handle the url you provide and map it to the appropriate application. Check out this tutorial: Configure Nginx as a web server
In your situation you could serve the angular app from the node application.
Check this too: How to serve an angular2 app in a node.js server
Related
Currently, I am developing an application that makes use of a fully dockerised Node API service (which is served locally by Docker Nginx) and a simple React front-end which is served locally using PHP valet.
Running docker-compose up, builds the dockerized application successfully hosted on Nginx on port 80 and proxy passes requests to the node API on port 9999.
The problem that I am having is getting the react front-end to communicate with the dockerised node API.
Ideally I would like to either; move the dockerized Node api service to be served by PHP valet or move the front-end webapp to also be served by the docker nginx service
How can I fully dockerize the front-end and back-end services together so that they can talk to each other (ideally both hosted on port 80) or alternatively suggest how I can use Valet or MAMP together with containerised Node API.
How can I fully dockerize the front-end and back-end services together so that they can talk to each other (ideally both hosted on port 80) or alternatively suggest how I can use Valet or MAMP together with containerised node API.
With or without Docker, you will be confronted to same origin policy for frontend requests to the backend (XMLHttpRequest and some other requests) since two URLs have the same origin if the protocol, port and host are the same.
If the two apps were containers, hosts would differ by design since these will be two distinct containers. And if you kept the frontend app on the host, it would be also the case.
So in any case, you should enable CORS in the backend side (NodeJS) for at least requests of the frontend host. From the frontend side, nothing should be needed since CORS is a browser stuff : it sends pre-flights requests to the target host to get resource sharing agreement.
About make the frontend a Docker container, I think that if the frontend is designed to work with the Node backend, you should probably also make that a docker image/container and use docker-compose to manage them : it will make them more simple to manage/maintain.
Build the front-end to static HTML and serve it from the backend from the static directory.
The React front-end is loaded on a user's machine and executes there in their browser. It communicates to the server over HTTP(S).
How are you serving the React app now? A React app is just plain text files that are served over HTTP.
Actually i have a server where there is hosted a website written in ASPX so it use IIS to run.
Now i would add an API that will permise to add some data to server database, the API is written in Node.JS so i was wondering if it's possible to run simultaneously Node and IIS.
Node is listening on port 3000 and obviously if i simply try to run 'websitedomain.it:3000/data' it doesn't work..
If something like this is possible how could i implement it?
Of course, you could run IIS and Node.JS simultaneously.
When you host webform website in IIS, it will not prevent node.js application being accessed.
You could self-host your node.js application then use URL rewrite rule and ARR to rewrite websitedomain.it:3000/data to your node.js api.
https://dev.to/petereysermans/hosting-a-node-js-application-on-windows-with-iis-as-reverse-proxy-397b
Of course, you could host your nodejs application in IIS with iisnode extension directly.
https://github.com/tjanczuk/iisnode/releases
I am working on a swift project for osx with Firebase. I have a node web server to communicate between the clients and the Firebase-server, but it's a localhost-server. Do I need a real domain name to make the server accessible to end-users on another device? (I don't want a web app, just the backend for myself)
you doesn't need a domain .. but you need a serve to deploy having ip address .. suggestion you can use cloud server
You have two ways:
make request on port that the nodejs uses, example http://101.01.01.01:8000
use nginx like proxy, in this setup make your requests on 80 port (it's default), example http://101.01.01.01.
If you wont make something like dev environment on local machine use first case (don't forgot open port for other devices), for production - second.
So I'm building an end to end application (With node.js/mysql back end, react front end, and using the express router), but I'm having trouble setting up a local development server. I don't need it to be accessed from the outside world, just be able to load different pages connecting to the express router. I don't have any dev ops experience for this, so I'm trying to use nginx to point it to the router which I can't figure out. Is there an easier way to do this?
I also need to run this on a windows machine, which just makes everything slightly more complicated
It's not entirely clear from your description how your application is set up and what the role of Nginx is.
So I'll start from the beginning...
Nginx is primarily an HTTP server which can also function as a proxy for HTTP requests. If you've written a Node.js application using Express, you have written an HTTP server which can handle any routes you have set up and can also serve your static assets (ie. HTML pages, images, front-end Javascript, CSS, etc.). In this case, there is no need for Nginx - if you wrote something like the Express "Hello World" app, then you will see a message like "Example app listening on port 3000" and you can connect to your app by visiting http://localhost:3000 in your browser.
That's it - there's literally nothing else to your app and there is no need for Nginx (or any other HTTP server) to run your application.
Now that's not to say that there is no role for Nginx in your application, but it may not be as an HTTP server. One possibility is that you may want to set up Nginx as a proxy, to handle certain routes by sending the requests to your Node application. For example, I set up an application some time ago which uses Nginx to proxy API routes for my application to a Node application and to serve static assets directly. This may be what you have in mind - if it is, you will need to configure different routes in Nginx to serve different things (and unfortunately there's not enough information in your question to give suggestions on this).
As an aside, you're probably going to find this much easier to set up using Linux - perhaps the Windows Linux Subsystem, a virtual machine running Linux, or Docker.
You'll probably want to use
https://github.com/facebook/create-react-app
create-react-app my-app will set up everything you need (webpack, etc.), and then
npm start will start a local development server.
Should work on Windows, but I don't know, because I wouldn't use/recommend Windows ;-)
context
I've a running app on Openshift using a nodejs (nodejs-0.10). I would like to add a ngix as first proxy to serve static files only.
problem
The question is how to add nginx to a running app on Openshift. I saw this cartridge gsterjov/openshift-nginx-cartridge but the README instructs how to create a new app using the nginx, but not how to add it to an existing app.
You can not add a secondary web framework cartridge to an application. Each application can only have one web framework cartridge installed at a time. You might need to setup a second application and setup nginx as a proxy if you want the requests to hit that first and serve static assets, then proxy the dynamic requests back to your node.js application.