how can I deploy my mern website from my local machine? - node.js

I have a fully functioning MERN app working. I was wondering, how would I deploy my mern app to the world wide web from my local machine?
My research has concluded with XAMPP as a possible tool, but it seems the backend tooling is PHP not nodejs. Any ideas you guys have helps!
the idea is to host it locally not externally on the cloud.

Firstly, you need to buy vps server. After you need to upload full project to the server through ftp software and need to upload packages with npm install/update. After these are finished download nginx server to the server and be carefull about port of project. If your project will running for example on 3000 port you may change nginx configuration like this and restart nginx with followed command:
systemctl restart nginx
and nginx configuration write like this (added example domain):
server {
listen 80;
listen [::]:80;
server_name yourdomain.com;
root /var/projects/your_project_name;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html;
charset utf-8;
location / {
proxy_pass http://localhost:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}
For additional information about nginx configurations you may visit Nginx configurations

Related

Node JS hosting using Nginx Reverse proxy gives 404 error

I want to host a Nodejs API server to my digitalocean server where a WordPress application is already running using Nginx and PHP fpm
I followed the below link to set up the WordPress application and it's working fine now.
https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-18-04-server
I wanted to set up Nodejs application inside the same server for demo purposes and I followed the digitalocean guide for setting up node js with a different config file and subdomain.
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
My Nginx config for node application looks like this
server {
server_name sub.domain.com
location / {
proxy_pass http://localhost:6969;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I have allowed port 6969 using ufw allow 6969.
I am able to access the Nodejs application using sub.domain.com:6969 but sub.domain.com gives me a 404 error. (404 Not Found nginx/1.18.0 (Ubuntu))
I want to access Nodejs application directly without a port number. I have checked Nginx logs and there are no errors, and configures is gives success in nginx -t
Please give me some suggestions to debug and fix this issue. I don't have much knowledge in Nginx configuration. I was just following tutorials from Digitalocean to configure the WordPress and node application.
Thanks in Advance
You are missing the port
server {
server_name sub.domain.com;
listen: 80;
location / {
proxy_pass http://localhost:6969;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

Deploy nuxt application on a nginx VPS server running ubuntu

I am trying to deploy a nuxt blog to a virtual private server that runs nginx.
The blog is supposed to be accessible when I browse to https://exampledomain.com/articles
I have managed to run npm run dev on the server successifully... The app is running on localhost:3000 on the server....
I need to set a reverse proxy on the server to redirect all requests from https://exampledomain.com/articles/ to localhost:3000
I have tried this twice and its failing.... When I browse https://exampledomain.com:3000 the app is loading forever.... when I go to https://exampledomain.com/articles it says "Page not working", or "Internal server error"
Kindly assist
This could be happening due to incorrect configuration.
Try
sudo nano /etc/nginx/sites-available/your-domain.com
Remember to change the your-domain.com to your desire domain
server {
listen 80;
listen [::]:80;
index index.html;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

Cors + Nginx + Nodejs (VUE Frontend + Backend) doesn't work

I have my backend Nodejs running on port 23456
I have my frontend VUE running on port 8080
When i start them and when i visit my domain eg. test.dev the frontend is visible however I'm not able to login.. and it feels like it's not triggering to DB at all.
The backend is starting fine, the fronend is starting fine, it just feels that they don't talk to each other since they are different ports.
For days I have been reading about this and this seems to be a CORS issue and i have tried to find right configt but since I'm noob in this nothing works.
I'm currently running NGINX and this is how my file looks like right now (etc/nginx/sites-available/test.dev.conf:
server {
listen 80;
server_name test.dev www.test.dev;
return 301 https://test.dev$request_uri;
}
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.dev www.test.dev;
# Use the Let's Encrypt certificates
ssl_certificate /etc/letsencrypt/live/test.dev/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/test.dev/privkey.pem;
# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:23456;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location / {
add_header 'Access-Control-Allow-Origin' 'http://localhost:8080' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'X-Requested-With,Accept,Content-Type, Origin' always;
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I can visit test.dev and I can see the frontend, however clicking on login doesn't work.
It feels like it's not connecting at all to the backend which is another port and I don't know how to get this to work..
This is the error in the console I'm getting:
Any idea how my .conf file should look like?
Thanks in advance.
I have managed to find the solution somehow.
So what i want to share is that the code above posted is correct.
Now, the solution was that I changed in the frontend VUE so that API was read from:
http://localhost:23456/api/v1
to
https://test.dev/api/v1
That's it. The login worked just find and everything works fine...
Thanks for all help!

asp.net core web app host on Linux Centos issues

I am new to Linux and read several articles to host asp.net core we applications on the Linux server. I have installed NGINX and modified /etc/nginx/sites-available/default. I ran this following command and it shows application started. I tried to check my application on the browser(using IP). It shows "502 Bad Gateway" error. I checked error log(/var/log/nginx/reverse_error.log) to see any errors. But it doesn't provide any relevant errors except http headers information. How to troubleshoot more on this issue?
$ sudo dotnet testapp.dll
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Production
Content root path: /var/www/testapp
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
/etc/nginxsites-available/default
server {
listen 80; # [::]:80;
listen [::]:80 ipv6only=on;
access_log /var/log/nginx/reverse_access.log;
error_log /var/log/nginx/reverse_error.log debug;
#rewrite_log on;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

Nginx + NodeJs - Limit port access to a server name

i’m new to the javascript world and im trying to publish online a small react app that i‘ve done for tests.
So, first i installed nodejs in my server that already has nginx. Then expressjs, configure it and made a nginx .conf file that uses proxy_reverse to access port 8080 (chosen for nodejs). When i access the server name of that .conf file, without the port, the page it’s shown correctly.
The problem is, if i access another server name configured in my server and add the 8080 port at the end, nginx shows me my nodejs app, even with a server name different from the one configured in proxy_reverse.
Is there any way to limit access to that specific port to one specific server name and return a error everywhere else?
My nginx conf file:
server {
listen 80;
server_name react.mydomain.com;
access_log /var/log/nginx/react.access.log;
error_log /var/log/nginx/react.error.log error;
location / {
proxy_pass https://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# Enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
}
Thanks

Resources