Parse Server es un Backend(Baas) que agiliza enormemente el desarrollo de aplicaciones a los desarrolladores, ya que incluye SDK para plataformas como Android, iOS, PHP, JavaScript y Unity, entre otros entornos disponibles. Así, el desarrollador puede evitar tener que crear una API, reduciendo drásticamente los tiempos de desarrollo.
Además, incluye funcionalidades como un dashboard para la administración, Push Notifications, integración de login de terceros como Facebook, Google o Apple, emails de registro y recuperación de contraseña, entre muchas otras características.
A continuación, te mostramos detalladamente los pasos necesarios para instalar Parse-Server, Parse-Dashboard y crear un certificado SSL Let's Encrypt junto a nGinx para segurizar las conexiones en un servidor Ubuntu 20.04 en Clouding.
Requisitos del entorno
- Ubuntu 20.04
- MongoDB
- NodeJS
- Yarn
- nGinx
- Let's Encrypt
Abrir puertos necesarios en el firewall de Clouding
Los puertos que utiliza Parse Server y Parse Dashboard son el 1337 y 4040 respectivamente. Sin embargo, como vamos a generar certificados SSL con Let's Encrypt deberás utilizar externamente los puertos 1338 para Parse Server y los puertos 80 y 443 para Parse Dashboard. Utilizaremos nGinx como servidor proxy que redireccionará a los puertos 1337 y 4040.
Firewall
Para abrir los puertos necesarios en el panel de Clouding puedes seguir los pasos del siguiente enlace Cómo crear una regla de firewall.El resultado debería ser como el siguiente:
Instalación MongoDB
Aunque Parse Server admite tanto MongoDB como Postgresql nos decidimos por la primera, debido a que es la que dispone mayor integración, rendimiento y facilidad con la configuración inicial al no tener que crearse ningún esquema inicial como en el caso de PostgreSql.
Para instalar MongoDB deberás ejecutar los siguientes comandos:
# apt update
# apt upgrade
# apt install mongodb-server -y
# systemctl status mongodb
root@parse-tutorial:~/parse-server# systemctl status mongodb
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-04-01 15:19:12 CEST; 29min ago
Docs: man:mongod(1)
Main PID: 554 (mongod)
Tasks: 34 (limit: 2280)
Memory: 180.7M
CGroup: /system.slice/mongodb.service
└─554 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf
Con estos comandos ya tendrás el servidor de base de datos preparado para que Parse Server pueda almacenar los datos.
Instalación de NodeJS junto al instalador de paquetes Yarn
Para poder desplegar tanto Parse-Server como Parse-Dashboard deberás instalar la última versión estable de NodeJS y para facilitar la instalación de ambos instalaremos el gestor de paquetes Yarn. Para ello deberás ejecutar la siguiente serie de comandos:
Añade el repositorio de NodejS.
# curl -sL https://deb.nodesource.com/setup_lts.x | bash -
Instala NodeJS en su última versión estable.
# apt install nodejs -y
Instala el gestor de paquetes yarn.
# npm install -g yarn
Comprueba la versión de Node instala.
# node --version
v14.16.0
Ahora ya tienes todas las dependencias previas para poder instalar Parse Server y el Dashboard.
Instalación de Parse Server
La instalación de Parse Server gracias al gestor de paquetes Yarn es realmente sencilla. Para ello deberás ejecutar el siguiente comando:
# yarn global add parse-server
Crea el fichero "config.json" donde especificarás la configuración del servidor Parse.
# mkdir parse-server
# cd parse-server
# vi config.json
Copia el siguiente contenido:
{
"appName": "Clouding Parse Server",
"databaseURI": "mongodb://localhost:27017/parsedb",
"appId": "418627a8-de68-4989-ad28-5dc5802887eb",
"javascriptKey" : "418627a8-de68-4989-ad28-5dc5802887eb",
"restAPIKey" : "418627a8-de68-4989-ad28-5dc5802887eb",
"clientKey" : "418627a8-de68-4989-ad28-5dc5802887eb",
"masterKey": "4938193c-3d20-4243-9eb9-031ca1ce9f18",
"serverURL": "http://localhost:1337/parse",
"publicServerURL": "https://9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host:1338/parse",
"port": 1337
}
Inicia el servidor Parse.
# nohup parse-server config.json &
Comprueba que el puerto de Parse Server está en escucha.
# ss -ant | grep 1337
LISTEN 0 511 0.0.0.0:1337 0.0.0.0:*
Una vez instalado el servidor Parse puedes instalar el Dashboard para facilitar la administración diaria del servidor.
Instalación de Parse Server Dashboard
Al igual que en el apartado anterior, la instalación del Dashboard se realiza de forma sencilla con el siguiente comando:
# yarn global add parse-dashboard
Crea el fichero "parse-dashboard-config.json".
# vi parse-dashboard-config.json
Copia la siguiente configuración.
{
"apps": [
{
"serverURL": "https://9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host:1338/parse",
"appId": "418627a8-de68-4989-ad28-5dc5802887eb",
"masterKey": "4938193c-3d20-4243-9eb9-031ca1ce9f18",
"allowInsecureHTTP": "true",
"appName": "Clouding Parse App"
}
],
"users": [
{
"user":"Clouding",
"pass":"12345"
}
]
}
Inicia el Dashboard.
# nohup parse-dashboard --dev --config ./parse-dashboard-config.json &
Comprueba que el puerto de Parse Server está en escucha.
# ss -ant | grep 4040
LISTEN 0 511 0.0.0.0:4040 0.0.0.0:*
¡Perfecto! Ya tienes tanto el servidor Parse como el Dashboard instalados.
Instalación y configuración de nGinx
Deberás utilizar nGinx para que haga de proxy inverso para Parse Server y Parse Dashboard. Además, al hacerlo así te facilitará el trabajo para instalar certificados SSL y poder disfrutar de las renovaciones automáticas sin tener que acceder a configurar el servidor cada tres meses. Para ello deberás seguir los siguientes pasos:
Instala nGinx.
# apt install -y nginx
Comprueba el estado del servicio de nGinx.
# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-04-01 15:19:13 CEST; 49min ago
Para este ejemplo utilizamos el identificador que se incluye en cada VPS de Clouding. En este caso "9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host".
Crea el fichero para el nuevo dominio con el que trabajarás:
# vi /etc/nginx/sites-available/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
Copia la siguiente configuración. Como vemos el puerto 80 redirige al puerto 4040 del dashboard y el puerto 1338 redirige al puerto 1337 del servidor parse.
server {
listen 80;
server_name 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host;
location / {
proxy_pass http://127.0.0.1:4040/;
}
}
server {
listen 1338;
server_name 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host;
location / {
proxy_buffers 8 32k;
proxy_buffer_size 64k;
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://127.0.0.1:1337/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 300;
}
}
Crea el enlace simbólico para activar el nuevo sitio.
# ln -s /etc/nginx/sites-available/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host /etc/nginx/sites-enabled/
Comprueba que la configuración sea correcta.
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reinicia el servicio de nGinx.
# systemctl restart nginx
Una vez tienes el servidor de nGinx configurado puedes crear el certificado SSL para poder utilizar el protocolo https.
Instalación del certificado SSL con Let's Encrypt
Deberás hacer uso de los certificados SSL de Let's Encrypt y para ello lo tendrás que instalar de la siguiente forma:
# apt install certbot python3-certbot-nginx
Crea el certificado para el dominio "9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host".
# certbot --installer nginx -d 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
Responde a las preguntas como se muestra a continuación. Deberás fijarte en que acabe bien con el mensaje "Congratulations! Your certificate and chain have been saved at:".
Saving debug log to /var/log/letsencrypt/letsencrypt.log
How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Nginx Web Server plugin (nginx)
2: Spin up a temporary webserver (standalone)
3: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 1
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): clouding@clouding.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host/privkey.pem
Your cert will expire on 2021-06-30. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Vuelve a editar el fichero "9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host" para editar el puerto 1338 para que también trabaje bajo SSL.
# vi /etc/nginx/sites-available/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host
Lo deberás editar para que quede como a continuación:
server {
server_name 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host;
location / {
proxy_pass http://127.0.0.1:4040/;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 1338 ssl;
server_name 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host;
location / {
proxy_pass http://127.0.0.1:1337/;
}
ssl_certificate /etc/letsencrypt/live/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name 9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host;
return 404; # managed by Certbot
}
¡Ya está! Ahora ya puedes acceder a tu Parse-Server y Parse-Dashboard de forma segura con certificado SSL de Let's Encrypt.
Acceder al Dashboard de Parse
Para acceder al Dashboard abre un navegador y accede a la URL https://9a5d1810-92bf-44f0-a0bd-a880724d9f96.clouding.host Allí deberás ver la siguiente ventana de login.
Introduce las credenciales configuradas anteriormente y haz clic en "Log In". Deberás ver el siguiente Dashboard con el que ya podrás empezar a trabajar.
Configuración de Parse-Server y Parse-Dashboard como servicio de sistema con Systemd
Para no tener que iniciar los servicios de Parse Server y Parse Dashboard manualmente cada vez que se reinicia el servidor ejecuta los siguientes pasos:
# cd /etc/systemd/system/
Crea el siguiente fichero de configuración de servicio.
# vi parse.server.service
Copia el siguiente contenido.
[Unit]
Description=Parse Server service
After=mongodb.service
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/usr/local/bin/parse-server /root/parse-server/config.json
[Install]
WantedBy=multi-user.target
Inicia y habilita el servicio.
# systemctl start parse.server.service
# systemctl enable parse.server.service
Haz los mismo para el servicio de Dashboard
# vi parse.server.dashboard.service
Copia la siguiente configuración.
[Unit]
Description=Parse Server Dashboard service
After=parse.server.service
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/usr/local/bin/parse-dashboard --dev --config /root/parse-server/parse-dashboard-config.json
[Install]
WantedBy=multi-user.target
Inicia y habilita el servicio.
# systemctl start parse.server.dashboard.service
# systemctl enable parse.server.dashboard.service
Comprobación de funcionamiento del entorno
Una de las formas más fáciles de comprobar que la instalación está funcionando correctamente es accediendo a tu Dashboard > API Console > Rest Console. Rellena los campos como a continuación te mostramos para crear un usuario nuevo y haz clic en "Send Query".
Dirígete a Browser > User y comprueba que el usuario creado se encuentra disponible.
Con los pasos detallados en este tutorial ya tienes tu propio servidor de Parse listo para desarrollar aplicaciones de forma más rápida y segura. ¡Esperamos que te haya servido de ayuda! :)