I'm little bit confused. I know how to serve user a dynamic page using Ejs with express. Usually when the user access the domain, the API in the domain responds with a page that is in the same domain. so we just have to host the API in a server.
Now i'm learning React on front-end and using express with MongoDB on the back-end. How to connect these front-end and back-end. How back-end serves the react app to the user. I searched on YouTube, but no one is talking about the back-end part, they are only talking about hosting the front-end part.
I don't know if i'm asking in the right way or not.but please help me.
The idea is to have one web-server to serve static files (the react app) and one API server (express) that exposes the API.
In order to consolidate both of these servers under one domain, you will need to use a Reverse Proxy. I would suggest using Nginx (inside docker).
+----------+
| |
| Client |
| |
+----+-----+
|
| myDomain.com
|
[INTERNET]
|
|
v :80
+--------+-------+
/* | | /api
+----------+ Revese Proxy +---------+
| | | |
| +----------------+ |
| :8080 | :3000
| |
+----+----------+ +---------+-----+
| | | |
| React | | Express |
| (webserver) | | (API server) |
| | | |
+---------------+ +---------------+
Any request to myDomain.com will be checked. If the path contains /api the request will be passed to the Backend. any other request will be passed to the webserver that contains the SPA static file.
Related
I have a web application running in Azure AKS. It has its own public DNS name and HTTPS configured.
But it has no authentication.
I want to authenticate users to access this application using built-in authentication feature of Azure App services and then proxy requests to my app in AKS.
I have installed a nginx_proxy in Docker and setup authentication. Authentication works, but in web browser I get 404 "No found" and does not reach application in AKS. Why?
The application itself is running fine and can be reached on its DNS name without proxy.
+----------------+ +------------+
| Azure | | Azure AD | Authnetication
| Kubernetes | +------------+
| app |
| (my.aks.io) | +-------------+
| | | App Service |
| | 404! | Docker | 200 ok
| |<-------https----| Nginx-proxy |<-------http-----
+----------------+ my.aks.io +-------------+
My Nginx proxy config
server {
listen 80;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://my.aks.io;
}
}
I am running different bokeh apps on different ports on my virtual machine using nginx. For example:
bokeh serve app1 --address 127.0.0.1 --port 5001
bokeh serve app2 --address 127.0.0.1 --port 5002
The nginx is configured so the each app corresponds to a different location. For example:
server {
location app1 {
proxy-pass https://localhost:5001/app1;
....
}
location app2 {
proxy-pass https://localhost:5002/app2;
....
}
}
How can I list out all ports and app locations?
Expected result:
> app1 runs on port 5000
> app2 runs on port 5001
I have tried netstat -tulpn | grep '127.0.0.1' but from that I can retrieve only the active ports and not the name of the app.
Why I need this? My apps are invoked automatically and run on predefined range of ports. I would like to monitor at each time which app is running on which port.
----- UPDATE
I manage to get the desired output, using:
ps -ef | grep "bokeh serve" | awk '$8~"python" {print $15 " " $11}'
but isn't there a nicer way? (like a bokeh serve monitor?)
do you consider using supervisord ? as daemon management? to running your app...
then you can code using http://supervisord.org/api.html
for get the status...
Deploying the first one was relatively easy, I just moved the folder to the server and using 'strapi start' and 'npm start' from linux terminal gets it up and running.
Now I would like to add an additonal strapi project to a sub directory and run in, so it's accessible from the url mysite/second-project.
But how can I run another project simultanouesly?
Thanks in advance
You probably can't use the <Host-Name>:80 to point towards two different strapi application since they run on different ports.
What you can do is specify your ngix or apache config to redirect specific folder structure to different strapi applications on different ports.
Suppose you have one application running on port 8080 and another application on port 8181 and then configure you nginx so that the incoming urls are redirected in such way:
+--- host --------> strapi application on localhost:8080
|
users --> nginx --|--- host/second-project ---> strapi application on localhost:8181
|
+--- host/mail ---> strapi application on localhost:8282
I need accept https from client and my backend is also https.
How can listen HTTPS in varnish and forward request to backend in HTTPS?
VARNISH_LISTEN_PORT=443
# how to add SSL certs?
Varnish, at least in the open source version, does not support HTTPS. Varnish Software released Hitch a while ago, which can be used to terminate HTTPS in front of a Varnish caching proxy. Many setups that I have seen also use nginx for SSL termination with varnish as backend.
I just found out that the commercial product Varnish Plus in fact supports TLS/SSL.
Hitch is opensource and infact supports SSL termination and can be used as Proxy for converting your HTTP server to HTTPS server.
Following is the guide and example, here openstack running on HTTP has been converted into HTTPS for all communication.
Create a VM(will be used as proxy node):
Download Hitch at Proxy Node:
git clone https://github.com/varnish/hitch.git
official link: https://github.com/varnish/hitch
Install HITCH as shown below:
To install hitch, Docs can be followed from the official link, below are the commands anyways.
$ ./bootstrap
$ ./configure
$ make
$ sudo make install
After successuful installation of HITCH, prepare certificate for the Proxy Node(.pem file)
Start the Proxy using HITCH as shown below.
[root#testing_tools hitch]# hitch --tls -f "[*]:443" -b "[2001::29]:80" devstack.pem -u hitch -g hitch
[root#testing_tools hitch]# hitch --tls -f "[*]:9696" -b "[2001::29]:9696" devstack.pem -u hitch -g hitch
Make Following changes(keystone Database) at Openstack end for endpoints. ie. make all endpoints configured for HTTPS.
mysql> select * from endpoint;
+----------------------------------+--------------------+-----------+----------------------------------+-------------------------------------------------+-------+---------+-----------+
| id | legacy_endpoint_id | interface | service_id | url | extra | enabled | region_id |
+----------------------------------+--------------------+-----------+----------------------------------+-------------------------------------------------+-------+---------+-----------+
| 01c5333a2edf4505a14987770a762a8a | NULL | public | f883c99bc5514dd6b8d3b417fb8a121c | https://devstackipv6/volume/v1/$(project_id)s | {} | 1 | RegionOne |
| 1766694b9c5b4814a421a074d44b2d32 | NULL | admin | 68a37fb109aa4f878f893fc87c262f94 | https://devstackipv6/heat-api-cfn/v1 | {} | 1 | RegionOne |
| 29e5c59cd68443d6beb96272b2d57143 | NULL | internal | eff63e56a0264b08a4cc9dc5de4ac8c4 | https://devstackipv6/heat-api/v1/$(project_id)s | {} | 1 | RegionOne |
+----------------------------------+--------------------+-----------+----------------------------------+-------------------------------------------------+-------+---------+-----------+
I'm using PowerDNS (2.9.22) for my clients. Because it can store all data into MySQL database and it's easy for clients to edit their zones as they like.
Now I have a problem with CNAMEs:
Here are records into MySQL database:
+-----------------------+-------+-----------------------+
| localhost.example.com | A | 127.0.0.1 |
+-----------------------+-------+-----------------------+
| a.example.com | CNAME | localhost.example.com |
+-----------------------+-------+-----------------------+
| www.example.com | CNAME | andreyzentavr.com |
+-----------------------+-------+-----------------------+
PowerDNS config is here:
allow-recursion=127.0.0.1, 173.193.**.162, 173.193.**.163
allow-recursion-override=on
cache-ttl=20
config-dir=/etc/powerdns
daemon=yes
default-soa-name=ns3.bserver.com
disable-axfr=yes
guardian=no
launch=gmysql
gmysql-host=127.0.0.1
gmysql-port=3306
gmysql-user=powerdns
gmysql-dbname=powerdns
gmysql-password=123123
lazy-recursion=yes
local-address=173.193.**.162, 173.193.**.163
local-port=53
log-dns-details=yes
log-failed-updates=yes
logfile=/var/log/pdns.log
loglevel=6
master=yes
max-queue-length=5000
max-tcp-connections=10
module-dir=/usr/lib/powerdns
query-logging=yes
recursor=127.0.0.1:53
setgid=pdns
setuid=pdns
skip-cname=no
slave=yes
slave-cycle-interval=600
soa-minimum-ttl=3600
soa-refresh-default=10800
soa-retry-default=3600
soa-serial-offset=0
socket-dir=/var/run
use-logfile=yes
wildcards=yes
version-string=powerdns
when I'm doing nslookup query, I got this:
server:~# nslookup
> set q=any
> server ns3.***.com
Default server: ns3.***.com
Address: 173.193.**.163#53
> a.example.com
Server: ns3.***.com
Address: 173.193.***.163#53
a.example.com canonical name =localhost.example.com.
Name: localhost.example.com
Address: 127.0.0.1
>
>
> www.example.com
Server: ns3.***.com
Address:
173.193.***.163#53
** server can't find www.example.com: NXDOMAIN
As you can see, if CNAME points to INTERNAL record - everything resolves fine. But if it points to external domain - I have an error.
andreyzentavr.com is existant domain and points to 194.126.204.41
Is it bug in PowerDNS? Or did I configure it wrongly?
Solution is to put the recursor in front of the authoritative server and configure the recursor to forward specific domains to the authoritative server using the forward-zones-recurse directive. Requires version 3.2 of the recursor.
Usually, with DNS, if you want to point a CNAME to an external record, you have to add a period to the end of the record (sub.domain.com.). When you leave off the final dot, DNS interprets it as a relative record (so sub.domain.com would be interpreted as sub.domain.com.domain.com, for example).
I would assume since you have an 'A' record for localhost.example.com set up in your database, PowerDNS sees that and knows that's the domain you mean to point to, even though you didn't make the other CNAME absolute (localhost.example.com.) or relative (just localhost in the hostname).