Deploying two angular application on a single aws ec2 istance - node.js

Trying to deploy two angular application (First one is for front end user interface, second one is for admin panel) for my ecommerce web platform on aws ec2 istance NGINX server.
server {
charset utf-8;
listen 80 default_server;
server_name _;
# angular app & front-end files
location / {
root /opt/app-web;
try_files $uri /index.html;
}
#admin app
location /app-admin/ {
root /opt/app-admin;
try_files $uri /index.html
}
# node api reverse proxy
location /api/ {
proxy_pass http://localhost:4000/;
}
}
Here I am unable to open the admin panel as it redirects to app-one. If there, Please suggest me a better way.

Related

NginX server more than already build react app under the same domain

I have a trouble serving under the same domain more than one React already built app( so in fact just a static files)
I have a config like below
server {
listen 80;
listen [::]:80;
root /var/www/xxx.xxx.xxx.xx; <IP
location /portfolio {
try_files /portfolio$uri /portfolio$uri/ =404;
}
location /portfolio2 {
try_files /portfolio2$uri /portfolio2$uri/ =404;
}
}
under the path > /var/www/xxx.xxx.xxx.xx i have 2 folders portfolio and portfolio2 which have build react code inside of each path
Thx a lot for response

ReactJS Router Dom not navigating to dashboard after logging in

Please help. I have my ReactJS NodeJS deployed on Linux NGINX and I can login on my development machine, on my phone, and on Linux OS running on my computer Oracle VM; i can accessed the application on these devices and it worked fine even when I changed IP address but immediately another device e.g somebody else computer or phone tries to login, it would always not redirect to dashboard but my three devices(laptop, phone, and Linux OS running on my computer Oracle VM) can redirect successfully to dashboard after logging in.
I have tried everything on this page below that people provided as solution but to no success :
https://stackoverflow.com/questions/43951720/react-router-and-nginx
Infact, i don't even see their login attempt in the NodeJS API running. My ReactJS build file contents are in /etc/nginx/sites-available/mydomain/ and this is my nginx.config below:
user www www; ## Default: nobody
server { # simple reverse-proxy
listen 80;
server_name mydomain;
# serve static files
#location ~ ^/(images|javascript|js|css|flash|media|static)/ {
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /etc/nginx/sites-available/mydomain;
index index.html;
try_files $uri /index.html;
}
location /api {
proxy_pass https://localhost:8084;
root /etc/nginx/sites-available/mydomain;
index index.html;
}
}
server {
listen 443 ssl;
server_name mydomain;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /etc/nginx/sites-available/mydomain;
index index.html;
try_files $uri /index.html;
}
location /api {
proxy_pass https://localhost:8084;
root /etc/nginx/sites-available/mydomain;
index index.html;
}
ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot;
ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
#...
}
Please fams, what difference does it make as I have my NGINX configuration in nginx.conf and not default?
As I configured my nginx.conf do I still need to go do the same in /etc/nginx/sites-available/default and what extension is this default config file?

ReactJS NodeJS Nginx deployment issue

I have my ReactJS NodeJS deployed on Linux NGINX and I can login on my development machine, on my phone, and on Linux OS running on my computer Oracle VM; i can accessed the application on these devices and it worked fine on these three devices even when I changed IP address but immediately another device e.g somebody else computer or phone tries to login, it would always return invalid login credentials but my three devices(laptop, phone, and Linux OS running on my computer Oracle VM) can login successfully on this application.
Below is my nginx.conf that manages my ReactJS NodeJS application
user www www; ## Default: nobody
server { # simple reverse-proxy
listen 80;
server_name mydomain;
root /etc/nginx/sites-available/mydomain;
index index.html;
# serve static files
#location ~ ^/(images|javascript|js|css|flash|media|static)/ {
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.html $uri/ =404;
}
location /api {
proxy_pass https://localhost:port;
}
}
server {
listen 443 ssl;
server_name mydomainname
root /etc/nginx/sites-available/mydomain;
index index.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.html $uri/ =404;
}
location /api {
proxy_pass https://localhost:port;
}
ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot;
ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
ssl_verify_client on;
}
I will appreciate your help.

Node.js app and Apache php back-end at the same server

I have a VPS which runs under CentOS 7.
The idea is: to have under maindomain.com node.js front-end app deployed while under api.maindomain.com to have php back-end deployed. Is it possible? Say, add server blocks to Nginx: reverse proxy localhost:4000 for node.js app and the other block for localhost:80 for php back-end.
Maybe there exists the other solution, I don't know, I would appreciate any ideas! The main goal: to have both app at the same server.
Solution 1 with www.maindomain.com + api.maindomain.com
Frontend
server {
listen 80;
server_name www.maindomain.com;
location / {
root /path/to/your/files;
try_files /index.html;
}
}
Backend php API
server {
listen 80;
server_name api.maindomain.com;
location / {
proxy_pass http://localhost:4000;
}
}
Solution 2 everything on same domain, www.maindomain.com
server {
listen 80;
server_name www.maindomain.com;
location /api {
proxy_pass http://localhost:4000/api;
}
location / { # always at the end, like wildcard
root /path/to/your/files;
try_files /index.html;
}
}

Refreshing page always resolves to top level

I am deploying my app on an ec2 machine. There is a node app which corresponds to myapp.com/api. This is working fine. The Client app is built on React and users visit it on myapp.com.
The client app is getting rendered and i am able to navigate to different paths. However when I refresh a page, eg. myapp.com/profile it always resolves to myapp.com.
server {
listen 80;
server_name myapp.com;
root /home/ec2-user/projects/synaid/client/build;
passenger_enabled on;
index index.html;
location / {
root /home/ec2-user/projects/synaid/client/build;
try_files $uri /index.html;
}
location /api {
root /home/ec2-user/projects/synaid/server/build;
rewrite ^/api/(.*) /$1 break;
passenger_enabled on;
passenger_app_type node;
passenger_app_root /home/ec2-user/projects/synaid/server/build;
passenger_startup_file index.js;
passenger_env_var APP_ENV staging;
}
}
What I thing is happening is that when nginx server gets a request it is slicing the url from base path and rendering the index.html to browser. It should also be passing the url forward to the app, which it doesnt seem to be doing.
A possible solution could be to forward url to the app from inside the configuration.

Resources